看看下面的SQL语句
有错,
我一下不知道怎么改
请大家帮忙
谢谢
select count(*) from 
(select  a.associator_number,a.name,
d.blockID,b.serviceID,b.ItemName,b.Money,convert (nvarchar(10),b.BuyDateTime,120)as BuyDateTime,
c.DeptName,a.handset_number,a.tel_number
from 
tb_Associator_Message a,tb_ConsumeCar b,tb_departments c  ,tb_AssociatorCard d 
where a.associator_number=d.associator_number and a.DeptId = c.DeptID and b.blockID = d. blockID)

解决方案 »

  1.   

    select count(*) from 
    (select  a.associator_number,a.name, 
    d.blockID,b.serviceID,b.ItemName,b.Money,convert (nvarchar(10),b.BuyDateTime,120)as BuyDateTime, 
    c.DeptName,a.handset_number,a.tel_number 
    from 
    tb_Associator_Message a,tb_ConsumeCar b,tb_departments c  ,tb_AssociatorCard d 
    where a.associator_number=d.associator_number and a.DeptId = c.DeptID and b.blockID = d. blockID)G
      

  2.   

    可以直接在内层使用count,
    不用使用子查询的,如:
    select  count(*) from tb_Associator_Message a,tb_ConsumeCar b,tb_departments c  ,tb_AssociatorCard d 
          where a.associator_number=d.associator_number and a.DeptId = c.DeptID and b.blockID = d. blockID
    如果非要使用的话,子查询后面加一个别名如:
    select count(*) from 
    (select  a.associator_number,a.name,d.blockID,b.serviceID,b.ItemName,b.Money,
            convert (nvarchar(10),b.BuyDateTime,120)as BuyDateTime, c.DeptName,a.handset_number,a.tel_number 
           from tb_Associator_Message a,tb_ConsumeCar b,tb_departments c  ,tb_AssociatorCard d 
           where a.associator_number=d.associator_number and a.DeptId = c.DeptID and b.blockID = d. blockID) A -- 加个A
      

  3.   

    子查询需要别名, 加在‘d. blockID)’ 后面