作者MerrickJiang ()
看板Database
标题[SQL ] decode用法
时间Sat May 10 22:28:06 2014
各位大大好,假设现在我统计要某一栏特定值的总和,
情境假设如下:
Table 名称: aa
name value
-----------
a 100
a 101
b 200
c 300
c 301
Select sum(decode(name,'a',1,0)) as a,
sum(decode(name,'b',1,0)) as b,
From aa
查询结果为 a b
------
2 1
想请问有没有在查询时用decode更缩短的用法
或是比sum(decode(...))更好的写法?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 119.14.94.195
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Database/M.1399732089.A.B50.html
1F:→ iFEELing:select count(name),name from aa ? 05/11 17:23