Skip to main content

3 posts tagged with "SQL"

View All Tags

· 5 min read
Alec.Ji

Question

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

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

· 4 min read
Alec.Ji

先上个官方说明
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.

简单理解,就是把一个查询结果临时存到指定的表达式上,这个表达式就叫公用表表达式 CTE(Common Table Expression)。 可以简单理解为一个不会实际创建的视图。

· One min read
Alec.Ji
  • SQL
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'))
  • Result
000050