sql语句
#
踟蹰千年
希望能一直有码编的码农一枚
展开
-
sql语句(group by原理)
所有select的字段,除聚合函数中的字段,都必须在group by中出现举个例子,select A,B,C,count(D),sum(E)from table group by A,B,C。除聚合函数count(D),sum(E)外,字段A,B,C必须在group by中出现。 为什么不能够select * from Table group by id,为什么一定不能是*,而是某一...原创 2019-02-27 12:46:21 · 2309 阅读 · 4 评论 -
sql语句(left join,inner join,right join,outer join)
对于SQL的Join,在学习起来可能是比较乱的。我们知道,SQL的Join语法有很多inner的,有outer的,有left的,有时候,对于Select出来的结果集是什么样子有点不是很清楚。Coding Horror上有一篇文章,通过文氏图 Venn diagrams 解释了SQL的Join。我觉得清楚易懂,转过来。假设我们有两张表。Table A 是左边的表。Table B 是右边的表。其各...转载 2019-02-27 12:48:47 · 1204 阅读 · 0 评论 -
sql语句(case when then else end用法)
Case具有两种格式。简单Case函数和Case搜索函数。 --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END --Case搜索函数 CASE WHEN sex = '1' THEN '男' WHEN sex = '2' THEN '女' ...转载 2019-02-27 13:48:30 · 13896 阅读 · 0 评论 -
sql语句(数据库中表和表自己本身关联查询)
例子1:select a.name 城市,b.name 地区,c.name 乡镇,d.name 道路 from address ajoin address b on b.parentid = a.idjoin address c on c.parentid = b.idjoin address d on d.parentid = c.idwhere d.name =...转载 2019-02-27 13:53:14 · 10092 阅读 · 0 评论