有一条SQL:select count(distinct a,b,c,d) from A.
执行出错,distinct中只有一个字段是执行成功。
现在不能用子查询如:select count(*) from (select distinct a,b,c,d from A)
请问有没有什么其他办法解决?
执行出错,distinct中只有一个字段是执行成功。
现在不能用子查询如:select count(*) from (select distinct a,b,c,d from A)
请问有没有什么其他办法解决?
select count(distinct a+'|'+b+'|'+c+'|'+d) from A
select count(distinct isnull(rtrim(a),'')+'|'+isnull(rtrim(b),'')+'|'+isnull(rtrim(c),'')+'|'+isnull(rtrim(d),'')) from A
mack
goselect distinct emp_id, fname, minit, lname
from employee
where fname = 'Aria'select count(*) as [count]
from ( select distinct emp_id, fname, minit, lname
from employee
where fname = 'Aria')
as a
--Resultemp_id fname minit lname
--------- -------------------- ----- ------------------------------
A-C71970F Aria Cruz(1 件処理されました)count
-----------
1(1 件処理されました)==我觉得楼主的代码有点小问题而已
select count(*) from (select distinct a,b,c,d from A)
==〉select count(*) from (select distinct a,b,c,d from A) as B
这样可能就对了
select count(*) from (select distinct a,b,c,d from A)
==〉select count(*) from (select distinct a,b,c,d from A) as B
这样可能就对了——————————————————————————————赫赫,我只是想说,不能嵌套子查询而已。
这条语句是错误的,COUNT不能这样用
select count(*) from (select distinct a,b,c,d from A)
这条也是错误的,如果在子查询后面加个别名,如下:select count(*) from (select distinct a,b,c,d from A) b
应该没有问题了
这样就可以了.
不是不能这样写,而是写的不对,子查询需要有别名的呀.