SQL - 减少SELECT和WHERE子句中的重复

时间:2016-03-09 16:53:40

标签: sql performance readability

原谅暧昧的头衔。但有没有办法可以通过以下查询减少SQL中的重复:

SELECT LTRIM(RTRIM(Address1))
FROM Customers
WHERE LTRIM(RTRIM(Address1)) = Address2

注意LTRIM(RTRIM(Address1))是否重复?我可以避免这个

1 个答案:

答案 0 :(得分:4)

正确的方式:

修剪您的数据并尽可能以干净的形式存储。

或者使用子查询并确定它是否更具可读性:

SELECT Address1
FROM (SELECT LTRIM(RTRIM(Address1)) AS Address1, Address2
      FROM Customers) AS sub
WHERE Address1 = Address2