C# 如何合并两个select查询?
我解决了那个问题。。。但现在我必须合并这两个查询:C# 如何合并两个select查询?,c#,sql-server,C#,Sql Server,我解决了那个问题。。。但现在我必须合并这两个查询: (SELECT Zila, COUNT(AbhidayMaster.OfficeRegId) As AbhidayPaidSansthan, SUM(AbhidayMaster.TotalEmp) As TotalWorkerPaid FROM PanjikaranMaster, AbhidayMaster WHERE PanjikaranMaster.OfficeRegId=AbhidayMaster.OfficeRegId AND Abhi
(SELECT Zila,
COUNT(AbhidayMaster.OfficeRegId) As AbhidayPaidSansthan,
SUM(AbhidayMaster.TotalEmp) As TotalWorkerPaid
FROM PanjikaranMaster, AbhidayMaster
WHERE PanjikaranMaster.OfficeRegId=AbhidayMaster.OfficeRegId
AND AbhidayMaster.DipositDate Between ('2012-06-22') AND ('2012-09-19') GROUP BY Zila)
Select
((SELECT count(distinct OfficeRegId) FROM PanjikaranMaster)
-
(SELECT count(distinct OfficeRegId) FROM AbhidayMaster)) As AbhidayNotPaidSansthan
那么:
SELECT
Zila,
COUNT(AbhidayMaster.OfficeRegId) As AbhidayPaidSansthan ,
SUM(AbhidayMaster.TotalEmp) As TotalWorkerPaid
FROM
PanjikaranMaster
INNER JOIN
AbhidayMaster ON PanjikaranMaster.OfficeRegId = AbhidayMaster.OfficeRegId
WHERE
AbhidayMaster.DipositDate BETWEEN '20120622' AND '20120919'
GROUP BY
Zila
我更改了连接语法,以使用正确的ANSI/ISO标准连接—一种显式的内部连接
,连接条件就在它所属的位置(请参阅了解为什么“旧式”连接是一个非常糟糕的主意,应该避免)
我还将您的日期字符串文字更改为语言-和区域设置安全-格式为
YYYYMMDD
(无破折号!)@user1673240:请不要将代码示例或示例数据放入注释中-因为您无法对其进行格式设置,所以很难阅读它。。。。取而代之的是:通过编辑你的问题来更新它,以提供额外的信息!谢谢你。谢谢你的帮助。。。。。。那个问题已经解决了。。我又一次陷入另一个问题。。请参阅以上更新的查询。