我有以下查询
SELECT
dtc.coupon_type_company_name,
COUNT(*) * dtc.coupon_type_company_coupon_amount AS 'Total_Coupon_To_Be_Used',
dtc.coupon_type_company_coupon_months_combinable
FROM
[dbo].[coupon_type_Company_User] dtcu
JOIN
coupon_type_Company dtc ON dtcu.coupon_type_Company_ID = dtc.id
JOIN
person p ON dtcu.userID = p.userID
WHERE
coupon_type_company_coupon_is_combinable = 1
OR coupon_type_company_has_coupon = 1
AND dtc.companyID = 1081
AND p.is_active = 1
GROUP BY
dtc.coupon_type_company_name,dtc.coupon_type_company_coupon_amount,
dtc.coupon_type_company_coupon_months_combinable
这将返回以下内容:
但是,我想要的只是一列和一行,应该取中间列(
count(*)*dtc.coupon_type_company_coupon_amount
)的总和。如何在我的代码后端(C#)中实现并防止这样做
最佳答案
您可以像这样包装查询:
SELECT SUM(Total_Coupon_To_Be_Used) AS the_sum
FROM (
your query
) s