您的位置:首页 > 其它

select进阶

2015-08-25 22:40 190 查看
(1)使用case来表达update

update my_table
set new_column=
case
when column1=somevalue1
then newvalue1
when column2=somevalue2
then newvalue2
else  newvalue3
end;


(2)排序——order by

默认为升序(ASC)排序,降序可在列名后面加“DESC”

按多列排序,中间用逗号隔开

(3)加总、平均、最大、最小、分组

SUM、AVG、MAX、MIN、group by

以上函数可以单独使用,也可以结合使用

(4)计数、独一无二

count、distinct

两者结合使用

select count(distinct sale_date)
from cookie_sales;


(5)限制查询结果的数量——limit

limit 2
为只输出两条结果

两个参数
limit 0,4
,0代表查询的起始处,4代表返回查询结果的数量。

注:SQL是0开始
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: