Create an inline SQL table on the fly (for an excluding left join)

后端 未结 4 1631
庸人自扰
庸人自扰 2020-12-13 09:26

Let\'s assume the following:

Table A

id | value
----------
1   | red
2   | orange
5   | yellow
10  | green
11  | blue
12  | indigo
20  | violet
         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 10:05

    You can do this from SQL Server 2008 onwards using a table value constructor.

    SELECT * FROM (
       VALUES(1, 'red'),
             (2, 'orange'),
             (5, 'yellow'),
             (10, 'green'),
             (11, 'blue'),
             (12, 'indigo'),
             (20, 'violet'))
       AS Colors(Id, Value)
    

    More information here: Table Value Constructor

提交回复
热议问题