SQL语句:
SELECT
R1.RSLTS_CONFIG_AGE_ID
, SUM(R1.PROV_AGE_GNDR_CNT) AS Prov_FeMaleCount
, SUM( R2.PROV_AGE_GNDR_CNT) AS Prov_Male_Count
FROM RESULTS_AGE_GENDER R1
INNER JOIN RESULTS_AGE_GENDER R2 ON R1.RSLTS_CONFIG_AGE_ID=R2.RSLTS_CONFIG_AGE_ID
WHERE R1.RSLTS_CONFIG_GNDR_ID=13
AND R2.RSLTS_CONFIG_GNDR_ID=14
GROUP BY R1.RSLTS_CONFIG_AGE_ID
答案 0 :(得分:-1)
在Linq扩展方法语法中完全相同的查询。
var res = context.RESULTS_AGE_GENDER
.Join(context.RESULTS_AGE_GENDER
, r1 => r1.RSLTS_CONFIG_AGE_ID
, r2 => r2.RSLTS_CONFIG_AGE_ID
(r1, r2) => r1r2)
.Where(x => x.r1.RSLTS_CONFIG_GNDR_ID == 13
&& x.r1.RSLTS_CONFIG_GNDR_ID == 14)
.GroupBy(x => x.r1.RSLTS_CONFIG_AGE_ID)
.Select(x => new
{
RSLTS_CONFIG_AGE_ID = x.Key,
Prov_FeMaleCount = x.Sum(y => y.r1.PROV_AGE_GNDR_CNT),
Prov_Male_Count = x.Sum(y => y.r2.PROV_AGE_GNDR_CNT)
});