如何在 where 中使用 (AS) TOTALNAME
SELECT
*, CITY + ' / ' + NAME AS TOTALNAME
FROM
FARKETMEZ
WHERE
TOTALNAME like '%TURKEY%'
如何在 where 中使用 (AS) TOTALNAME
SELECT
*, CITY + ' / ' + NAME AS TOTALNAME
FROM
FARKETMEZ
WHERE
TOTALNAME like '%TURKEY%'
您不能使用与子句ALIAS
处于同一级别的 that 。WHERE
你有两个选择:
询问:
SELECT *, CITY + ' / ' + NAME AS TOTALNAME
FROM FARKETMEZ
WHERE TOTALNAME like '%TURKEY%'
询问:
SELECT *
FROM
( SELECT *, CITY + ' / ' + NAME AS TOTALNAME
FROM FARKETMEZ
) a
WHERE TOTALNAME like '%TURKEY%'
SQL 操作顺序如下:
之所以不能直接使用,是因为子句在创建语句WHERE
之前先执行。SELECT
ALIAS
您不能直接使用派生表,也可以使用 CTE (SQL Server 2005+):
派生表:
SELECT *
FROM ( SELECT
*, CITY + ' / ' + NAME AS TOTALNAME
FROM
FARKETMEZ
) AS T
WHERE TOTALNAME like '%TURKEY%'
热电偶:
;WITH CTE AS
(
SELECT
*, CITY + ' / ' + NAME AS TOTALNAME
FROM
FARKETMEZ
)
SELECT *
FROM CTE
WHERE TOTALNAME like '%TURKEY%'