如果您没有将整个
CASE语句
GROUP BY包装在子查询中,则需要使用该语句中的整个语句。
SELECt CASE WHEN DATEDIFF(o.EndDate, o.StartDate) < 30 THEN '<1 Month' WHEN DATEDIFF(o.EndDate, o.StartDate) < 90 THEN '1 - 2 Months' WHEN DATEDIFF(o.EndDate, o.StartDate) < 210 THEN '3 - 4 Months' ELSE '>4 Months' END AS `Length`, COUNT(DISTINCT(person.ID)) AS `COUNT`FROM person INNER JOIN opportunity AS o ON person.EntityID = o.id INNER JOIN Organization AS org ON o.OrganizationID = Org.IDWHERe person.TitleID = 2 AND o.bID = 1GROUP BY CASE WHEN DATEDIFF(o.EndDate, o.StartDate) < 30 THEN '<1 Month' WHEN DATEDIFF(o.EndDate, o.StartDate) < 90 THEN '1 - 2 Months' WHEN DATEDIFF(o.EndDate, o.StartDate) < 210 THEN '3 - 4 Months' ELSE '>4 Months' ENDORDER BY Length ASC;
还要删除
ORDER BY子句中列名周围的单引号。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)