将 Postgres 交叉连接横向转换为 SQL 服务器代码
Converting Postgres cross join lateral to SQL server code
这是我当前的代码:
SELECT c.id,
t.vaccinedate,
t.vaccine,
t.vaccinesource,
t.num
FROM child c
CROSS JOIN LATERAL ( VALUES (c.bcgsource,c.bcgdate,'bcg'::text,1), (c.opv0source,c.opv0date,'opv0'::text,2), (c.penta1source,c.penta1date,'penta1'::text,3), (c.pcv1source,c.pcv1date,'pcv1'::text,4), (c.rota1source,c.rota1date,'rota1'::text,5)) t(vaccinesource, vaccinedate, vaccine, num)
如何将其转换为 SQL 服务器代码?因为我在 SQL server.
中找不到 Cross join lateral
我们可以尝试在 SQL 服务器
中使用 CROSS APPLY
而不是 CROSS JOIN LATERAL
SELECT c.id,
t.vaccinedate,
t.vaccine,
t.vaccinesource,
t.num
FROM child c
CROSS APPLY ( VALUES
(c.bcgsource, c.bcgdate, 'bcg', 1),
(c.opv0source, c.opv0date, 'opv0', 2),
(c.penta1source, c.penta1date, 'penta1', 3),
(c.pcv1source, c.pcv1date, 'pcv1', 4),
(c.rota1source, c.rota1date, 'rota1', 5)
) t(vaccinesource, vaccinedate, vaccine, num)
这是我当前的代码:
SELECT c.id,
t.vaccinedate,
t.vaccine,
t.vaccinesource,
t.num
FROM child c
CROSS JOIN LATERAL ( VALUES (c.bcgsource,c.bcgdate,'bcg'::text,1), (c.opv0source,c.opv0date,'opv0'::text,2), (c.penta1source,c.penta1date,'penta1'::text,3), (c.pcv1source,c.pcv1date,'pcv1'::text,4), (c.rota1source,c.rota1date,'rota1'::text,5)) t(vaccinesource, vaccinedate, vaccine, num)
如何将其转换为 SQL 服务器代码?因为我在 SQL server.
中找不到 Cross join lateral我们可以尝试在 SQL 服务器
中使用CROSS APPLY
而不是 CROSS JOIN LATERAL
SELECT c.id,
t.vaccinedate,
t.vaccine,
t.vaccinesource,
t.num
FROM child c
CROSS APPLY ( VALUES
(c.bcgsource, c.bcgdate, 'bcg', 1),
(c.opv0source, c.opv0date, 'opv0', 2),
(c.penta1source, c.penta1date, 'penta1', 3),
(c.pcv1source, c.pcv1date, 'pcv1', 4),
(c.rota1source, c.rota1date, 'rota1', 5)
) t(vaccinesource, vaccinedate, vaccine, num)