原谅暧昧的头衔。但有没有办法可以通过以下查询减少SQL中的重复:
SELECT LTRIM(RTRIM(Address1))
FROM Customers
WHERE LTRIM(RTRIM(Address1)) = Address2
注意LTRIM(RTRIM(Address1))
是否重复?我可以避免这个
答案 0 :(得分:4)
正确的方式:
修剪您的数据并尽可能以干净的形式存储。
或者使用子查询并确定它是否更具可读性:
SELECT Address1
FROM (SELECT LTRIM(RTRIM(Address1)) AS Address1, Address2
FROM Customers) AS sub
WHERE Address1 = Address2