尝试更改以下代码以允许我在where子句
中使用minSELECT od.personID
,'Uno' AS [CustomerType]
FROM dbo.orderDetails od
WHERE od.orderDate BETWEEN CONVERT(date, '2016-02-01') AND @StartDate
AND MIN(odd.orderDate) BETWEEN CONVERT(date, '2016-02-01') AND @StartDate)
GROUP BY personID
答案 0 :(得分:6)
将MIN
移至HAVING
部分
SELECT od.personID
,'Uno' AS [CustomerType]
FROM dbo.orderDetails od
WHERE od.orderDate BETWEEN CONVERT(date, '2016-02-01') AND @StartDate
GROUP BY personID
HAVING MIN(odd.orderDate) BETWEEN CONVERT(date, '2016-02-01') AND @StartDate