我需要在不同的表中使用不同的数据,因为我尝试了所有的代码,它们都是一个接一个地工作的,ı不是一起工作的,我尝试了两种方法,但是ıts和工作的ı都认为roung语法ıresarch,但是ı在sql中是新的。
我的第一条路:
string cmd = @" SELECT COUNT(Ref) AS data,";
cmd += @" (select count(CustomerID) as data2 from Contract where DATEDIFF(DAY,StartDate,GETDATE()) between 0 and 30),";
cmd += @" (select count(distinct(CustomerID)) as data3 from Contract where FinishDate > GETDATE()),";
cmd += @" (select count(Ref) as data4 from Support where DATEDIFF(DAY,StartDate,GETDATE()) between 0 and 30)";
cmd += @" FROM Customer WHERE (Deleted = 0 or Deleted is null) ";我的第二条路:
string cmd = @" SELECT COUNT(Ref) ,";
cmd += @" (select count(CustomerID) from Contract where DATEDIFF(DAY,StartDate,GETDATE()) between 0 and 30) as data2 ,";
cmd += @" (select count(distinct(CustomerID)) from Contract where FinishDate > GETDATE()) as data3,";
cmd += @" (select count(Ref) from Support where DATEDIFF(DAY,StartDate,GETDATE()) between 0 and 30) as data4";
cmd += @" FROM Customer WHERE (Deleted = 0 or Deleted is null) AS data ";发布于 2020-01-17 06:35:34
别名必须在查询级别分配,而不是在子查询(第一个变体)中分配。
其中条件不能有别名(第二个变体)。
SELECT COUNT(Ref) AS data,
( select count(CustomerID)
from Contract
where DATEDIFF(DAY,StartDate,GETDATE()) between 0 and 30) as data2 ,
( select count(distinct(CustomerID))
from Contract
where FinishDate > GETDATE()) as data3,
( select count(Ref)
from Support
where DATEDIFF(DAY,StartDate,GETDATE()) between 0 and 30) as data4
FROM Customer
WHERE (Deleted = 0 or Deleted is null) https://stackoverflow.com/questions/59782183
复制相似问题