sql查询集锦(一)

来源:互联网 发布:nokia n8软件下载 编辑:程序博客网 时间:2024/05/17 03:01

1.求表中3月份薪水增加的用户id。

userId       month       salary     
        1                2000            2

        1                3000            3

        1                4000            4

        2                2000            2

        2                2000            3

        2                2000            4

sql:select * from salary s1 left join salary s2 

on s1.`month` + 1 = s2.`month`  

where s1.month = 2 and s1.userid = s2.userid and s1.salary < s2.salary;

原创粉丝点击