-- 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‘) from
iteblog;
--得到 www.iteblog.com
==============substr(str,0,len) 截取字符串从0位开始的长度为len个字符。
select substr(‘abcde‘,3,2) from
iteblog;
-- 得到cd
==============