LEFT JOIN ON AND/WHERE

LEFT JOIN ON AND/WHERE

Question

这两个SQL查询的结果相同吗?

SQL
1
2
SELECT * FROM TableA a LEFT JOIN TableB b ON  b.AId =a.TableAId AND a.TableAId =1
SELECT * FROM TableA a LEFT JOIN TableB b ON b.AId =a.TableAId WHERE a.TableAId = 1
阅读更多

WITH common_table_expression

WITH common_table_expression

先上个官方说明
Specifies a temporary named result set, known as a common table expression (CTE). This is derived from a simple query and defined within the execution scope of a single SELECT, INSERT, UPDATE, or DELETE statement. This clause can also be used in a CREATE VIEW statement as part of its defining SELECT statement. A common table expression can include references to itself. This is referred to as a recursive common table expression.

阅读更多

SQL PadLeft

SQL PadLeft

  • SQL
1
2
3
PRINT RIGHT(CAST(REPLICATE('0', LEN(no_start)) + CAST(no_start + (inventory - 1) AS VARCHAR(50)) AS VARCHAR(50)), LEN(no_start))

PRINT RIGHT(CAST(REPLICATE('0', LEN('000001')) + CAST('000001' + (50 - 1) AS VARCHAR(50)) AS VARCHAR(50)), LEN('000001'))
阅读更多