作者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