MySQL常用语句

来源:互联网 发布:华南师大网络教育 编辑:程序博客网 时间:2024/06/03 17:09

1、查询第二高的薪水

select distinct salary as from employee order by salarylimit 1 offset 1

保证非空:

//IFNULL() functionselect IFNULL(select..., null);

或者

select (select...);

2、查询连续三个Num相同的记录

SELECT DISTINCT    l1.Num AS ConsecutiveNumsFROM    Logs l1,    Logs l2,    Logs l3WHERE    l1.Id = l2.Id - 1    AND l2.Id = l3.Id - 1    AND l1.Num = l2.Num    AND l2.Num = l3.Num;
原创粉丝点击