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

解决方案 »

  1.   

    try:
    select count(distinct a+'|'+b+'|'+c+'|'+d) from A
      

  2.   

    try:
    select count(distinct isnull(rtrim(a),'')+'|'+isnull(rtrim(b),'')+'|'+isnull(rtrim(c),'')+'|'+isnull(rtrim(d),'')) from A
      

  3.   

    楼上的方法好神奇啊......
    mack
      

  4.   

    select count(*) from (select distinct a,b,c,d from A) b
      

  5.   

    use pubs
    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
    这样可能就对了
      

  6.   

    ==我觉得楼主的代码有点小问题而已
    select count(*) from (select distinct a,b,c,d from A)
    ==〉select count(*) from (select distinct a,b,c,d from A) as B
    这样可能就对了——————————————————————————————赫赫,我只是想说,不能嵌套子查询而已。
      

  7.   

    Select COUNT(*) From A Group BY a,b,c,d
      

  8.   

    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
    应该没有问题了
      

  9.   

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