我在SQL Server 2008中工作。我必须在三个可能的字符串值中找到字符串类型的最小值。如果值来自表的单个列,我知道如何执行此操作。在我的例子中,它来自三个不同的别名。
这是SQL的一部分:
SELECT
CustomerId,
leaseType = (CASE
WHEN MIN(CONCAT(L1.LeaseType, L2.LeaseType, L3.LeaseType)) = 'T'
THEN 'Temporary'
WHEN MIN(CONCAT(L1.LeaseType, L2.LeaseType, L3.LeaseType)) = 'P'
THEN 'Permanant'
WHEN MIN(CONCAT(L1.LeaseType, L2.LeaseType, L3.LeaseType)) = 'U'
THEN 'Unknown'
ELSE ''
END)
FROM
Customer
INNER JOIN
(SELECT
CustomerId, LeaseType
FROM
Lease
WHERE
LeaseType = 'T') L1 ON L1.CustomerId = c.CustomerId
INNER JOIN
(SELECT
CustomerId, LeaseType
FROM
Lease
WHERE
LeaseType = 'P') L2 ON L2.CustomerId = c.CustomerId
INNER JOIN
(SELECT
CustomerId, LeaseType
FROM
Lease
WHERE
LeaseType = 'U') L3 ON L3.CustomerId = c.CustomerId
WHERE
CustomerId > 10000
但是,该查询不起作用。在其他错误中,它还抛出
'CONCAT‘不是可识别的内置函数名
https://stackoverflow.com/questions/55368150
复制相似问题