连接字符串: concat
条件逻辑: select col_a, case when col_b<100 then 'small' else 'big' end as state from sometable
按某个字段的最后两个字符升序:select col_a,col_b from sometable order by substring(col_b, length(col_b)-2)
重叠结果输出:[SELECT SQL A] union all [SELECT SQL B]
union all不删重复项;union删重复项;除非必要,否则不要用union、distinct
从一个表中取数据导入另一个表:insert into table1(col_a, col_b) select (col_aa, col_bb) from table2 where colcc='somevalue'
出现三次以上部门:select col_a from sometable group by col_a having count(*)>=3
列出索引:show index from emp
正则:select data from sometable where data regexp '[^0-9]' = 0
将同一部门的人名合在一行显示:select dept, group_concat(name order by id, ',') from emp group by dept
滚动结果集,每页五行(limit 5),显示第2页(offset 5):select col_a from sometable order by col_a limit 5 offset 5
没有评论:
发表评论