SQL总结
1.嵌套形式
where嵌套
select c1, c2 from table where c3 > (select c3 from table where c4 =5)
from嵌套
select a.c1, count1, count2
from (select c1, count(c1) as count1 from table where c4= 0 group by c1 order by c1 desc) a,
(select c1, count(c1) as count2 from table where c1 = 0 and c4 = 1 group by c1) b
where a.c1 = b.c1
2.条件判断
>, >=, !>, <, <=, !<, =, !=, <>, in, exist;
(> | >= | !> | < | <= | !< | = | != | <>) + (some | all | any)
3.计算公式
sum(colum), avg(colum), count(colum)
max(colum), min(colum), union(colum)
4.常用函数
convert(type, colum) 类型转换,
abs(colum) 绝对值,
ceiling(colum) ,ceil(colum) 取整大,
floor(colum) 取整小,
cast(colum) , trunc(colum) 取整、截取,
round(colum,num) 四舍五入保留 num 位小数,