首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

问Count?该如何解决

2011-12-29 
问Count?有一条SQL:selectcount(distincta,b,c,d)fromA.执行出错,distinct中只有一个字段是执行成功。现在

问Count?
有一条SQL:select   count(distinct   a,b,c,d)   from   A.
执行出错,distinct中只有一个字段是执行成功。
现在不能用子查询如:select   count(*)   from   (select   distinct   a,b,c,d   from   A)
请问有没有什么其他办法解决?

[解决办法]
try:
select count(distinct a+ '| '+b+ '| '+c+ '| '+d) from A
[解决办法]
学习了!
[解决办法]
有~~你==
[解决办法]
一下这么多人啦~~~算啦算啦~~~
[解决办法]
use pubs
go

select 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

--Result

emp_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(distinct a,b,c,d) from A.
这条语句是错误的,COUNT不能这样用
select count(*) from (select distinct a,b,c,d from A)
这条也是错误的,如果在子查询后面加个别名,如下:

select count(*) from (select distinct a,b,c,d from A) b
应该没有问题了



[解决办法]
select count(*) from (select distinct a,b,c,d from A) tt
这样就可以了.
不是不能这样写,而是写的不对,子查询需要有别名的呀.

热点排行