作者SureWin (surewin)
看板Database
標題Count(distinct(兩個欄位))??
時間Sun Feb 7 17:13:21 2010
請問一下
我在sql 2005
需要下一個sql command
ex:
select count(distinct(a1,a2)) from table where a2='xx'
不能run 好像distinct裡面不可以接受 兩個欄位
但是我的資料因為 a1 有可能是 null
所以
select count(distinct(a1) from table where a2='xx'
會算錯
所以我需要 a2 去帶出來 但那又不能run
請問有甚麼替代的 語法嗎 ?? 想很久一直解決不了
--
~~~哇尚無甲意"贏"ㄟ感覺~~~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 117.19.114.141
1F:推 LPH66:條件是a2='xx' 那distinct(a1,a2)和distinct(a1)應該一樣吧 02/07 21:14
2F:→ grence:a1 null為什麼會算錯?不要算 null就 where a1 is not null 02/07 21:35
3F:→ SureWin:distinct(a1) a1有可能是 null 所以才要把a2加進去 02/07 21:35
4F:→ SureWin:null對我來說也是一筆資料 直接distinct(a1)他部會算null 02/07 21:41
5F:推 rushcat:DISTINCT(ISNULL(a1, a2)) 試試看!? 02/08 00:23
6F:→ grence:distinct(isnull(a1, 不可能出現在a1的值)) int←→char 02/08 22:43