SELECT ma.ManningID
...
,'P01' AS Pline
...
FROM Manning AS ma
UNION ALL
SELECT ma.ManningID
...
,'P02' AS Pline
...
FROM Manning AS ma
UNION ALL
SELECT ma.ManningID
...
,'P03' AS Pline
...
FROM Manning AS ma
如果有很多P ...是否可以使这个视图的查询更紧凑?
答案 0 :(得分:3)
您可以使用table value constructor(通常在INSERT中使用),然后使用CROSS JOIN。
SELECT ma.ManningID
, ...
, p.Pline
, ...
FROM Manning ma
CROSS JOIN (VALUES ('P01'),('P02'),('P03')) P(Pline)
答案 1 :(得分:1)
此?
SELECT ma.ManningID
...
,Pline
...
FROM Manning AS ma
cross join (select 'p01' AS Pline
union 'p02'
union 'p03') c