我试图对别名列(以下示例)执行按操作分组,但无法确定正确的语法。
SELECT LastName + ', ' + FirstName AS 'FullName'
FROM customers
GROUP BY 'FullName'
正确的语法是什么?
编辑
进一步扩展问题(我没想到我会收到答案),解决方案是否仍适用于CASE别名列?
SELECT
CASE
WHEN LastName IS NULL THEN FirstName
WHEN LastName IS NOT NULL THEN LastName + ', ' + FirstName
END AS 'FullName'
FROM customers
GROUP BY
LastName, FirstName
答案是肯定的,它仍然适用。