首页 > 数据库技术 > 详细

sql示例

时间:2020-04-05 21:24:18      阅读:75      评论:0      收藏:0      [点我收藏+]

-- table_1中有id,age; table_2中有id,sex。想取出id,age,sex 三列信息,-- 将table_1,table_2 根据主键id连接起来
select a.id,a.age,b.sex from (select id,age from table_1) a join (select id, sex from table_2) b on a.id =b.id

 ================想知道有多少去重的用户数

select count(*) from(select distinct id from table_1) tb

================将数值型的变量转化为分类型的变量?—— case when 条件函数

-- 收入区间分组

select id,(case when CAST(salary as float)<50000 Then ‘0-5万‘when CAST(salary as float)>=50000 and CAST(salary as float)<100000 then ‘5-10万‘when CAST(salary as float) >=100000 and CAST(salary as float)<200000 then ‘10-20万‘when CAST(salary as float)>200000 then ‘20万以上‘else NULL end from table_1;

==============concat( A, B...)返回将A和B按顺序连接在一起的字符串

select concat(‘www‘,‘.iteblog‘,‘.com‘) fromiteblog;--得到 www.iteblog.com

==============substr(str,0,len) 截取字符串从0位开始的长度为len个字符。

select substr(‘abcde‘,3,2) fromiteblog;-- 得到cd

 ==============

 

sql示例

原文:https://www.cnblogs.com/testzcy/p/12638960.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!