以下是亲测可用的:
1.
select
name,max(id)
from
t1
group by
name;
select
name,max(id)
from
t1
group by
name;
这个结果挺明显的。选出每个name下某个id最大值
SQL取补集
1. select s1.mobile from table1 s1
where s1.mobile not in
(select s2.phone from table2 s2);
2. select s1.mobile from table1 s1
except
select s2.phone from table2 s2;
按时间顺序取最近的记录:
使用到row_number()over这个函数
SQL一些有用的函数:
1. coalesce(a, b, c, ...)
返回第一个不是null的值
2. add_months('2016-09', 1)
返回日期。比如上面会返回'2016-10'
3. substr('abcdefg', 2, 4)
截取字符串。比如上面会返回'bcd'