snowflake sql - 横向展平函数与 sql 服务器比较 - Split_String()
snowflake sql - lateral flatten function compare with sql server - Split_String()
我的任务是比较计数,看看它是否 > 0
下方sql雪花
select 'abc'
from tableA
where
(SELECT count(T1.value) as val
from tableA,
lateral flatten(input=>split(abc, ',')) T1
INNER JOIN (select count(T2.value) as val from
lateral flatten(input=>split('1,2', ','))) as T2 on T1.val = T2.val) > 0
这是错误消息
SQL compilation error: error line 7 at position 29 invalid identifier 'T2.VALUE'
Sql 有效的服务器比较。
(select Count(T1.value) as [Count] from STRING_SPLIT(abc,',') AS T1
INNER JOIN STRING_SPLIT('9,10', ',') AS T2 on T1.value = T2.value))>0
您可能需要像这样重新定位 -
select 'abc'
from tableA
where
(select count(*) from
(SELECT count(flat_tab_alias1.value) as val
from tableA,
lateral flatten(input=>split(abc, ',')) flat_tab_alias1
) as T1
INNER JOIN
(
select count(flat_tab_alias2.value) as val from
lateral flatten(input=>split('1,2', ',')) flat_tab_alias2
) as T2
on T1.val = T2.val) > 0;
'ABC'
0 Row(s) produced.
来源如下 table -
select * from tablea;
ABC
a,b,c,d,e,f,g
你 SQL 有很多问题,但鉴于我们正在努力 T-SQL 让我们解码它。
(select Count(T1.value) as [Count] from STRING_SPLIT(abc,',') AS T1
INNER JOIN STRING_SPLIT('9,10', ',') AS T2 on T1.value = T2.value))>0
这段代码正在拆分一个字符串数组,并将其连接到一组“已知”值,计算均值如何相等,并询问是否存在任何重叠。
ARRAY_OVERLAP 回答这个问题,并使用 SPLIT 制作数组:
SELECT abc,
split(abc, ',') as a1,
split('1,2', ',') as a2,
ARRAYS_OVERLAP( a1, a2)
FROM values
('1'),
('0,4'),
('0,1,5')
t(abc);
给出:
ABC
A1
A2
ARRAYS_OVERLAP( A1, A2)
1
[ "1" ]
[ "1", "2" ]
TRUE
0,4
[ "0", "4" ]
[ "1", "2" ]
FALSE
0,1,5
[ "0", "1", "5" ]
[ "1", "2" ]
TRUE
所以你的 SQL 应该是:
SELECT 'abc', abc
FROM tableA
WHERE ARRAYS_OVERLAP( split(abc,','), split('1,2',','));
其中包含虚拟数据:
select * from values
('1'),
('0,4'),
('0,1,5')
给出:
'ABC'
ABC
abc
1
abc
0,1,5
我的任务是比较计数,看看它是否 > 0
下方sql雪花
select 'abc'
from tableA
where
(SELECT count(T1.value) as val
from tableA,
lateral flatten(input=>split(abc, ',')) T1
INNER JOIN (select count(T2.value) as val from
lateral flatten(input=>split('1,2', ','))) as T2 on T1.val = T2.val) > 0
这是错误消息
SQL compilation error: error line 7 at position 29 invalid identifier 'T2.VALUE'
Sql 有效的服务器比较。
(select Count(T1.value) as [Count] from STRING_SPLIT(abc,',') AS T1
INNER JOIN STRING_SPLIT('9,10', ',') AS T2 on T1.value = T2.value))>0
您可能需要像这样重新定位 -
select 'abc'
from tableA
where
(select count(*) from
(SELECT count(flat_tab_alias1.value) as val
from tableA,
lateral flatten(input=>split(abc, ',')) flat_tab_alias1
) as T1
INNER JOIN
(
select count(flat_tab_alias2.value) as val from
lateral flatten(input=>split('1,2', ',')) flat_tab_alias2
) as T2
on T1.val = T2.val) > 0;
'ABC' |
---|
0 Row(s) produced.
来源如下 table -
select * from tablea;
ABC |
---|
a,b,c,d,e,f,g |
你 SQL 有很多问题,但鉴于我们正在努力 T-SQL 让我们解码它。
(select Count(T1.value) as [Count] from STRING_SPLIT(abc,',') AS T1
INNER JOIN STRING_SPLIT('9,10', ',') AS T2 on T1.value = T2.value))>0
这段代码正在拆分一个字符串数组,并将其连接到一组“已知”值,计算均值如何相等,并询问是否存在任何重叠。
ARRAY_OVERLAP 回答这个问题,并使用 SPLIT 制作数组:
SELECT abc,
split(abc, ',') as a1,
split('1,2', ',') as a2,
ARRAYS_OVERLAP( a1, a2)
FROM values
('1'),
('0,4'),
('0,1,5')
t(abc);
给出:
ABC | A1 | A2 | ARRAYS_OVERLAP( A1, A2) |
---|---|---|---|
1 | [ "1" ] | [ "1", "2" ] | TRUE |
0,4 | [ "0", "4" ] | [ "1", "2" ] | FALSE |
0,1,5 | [ "0", "1", "5" ] | [ "1", "2" ] | TRUE |
所以你的 SQL 应该是:
SELECT 'abc', abc
FROM tableA
WHERE ARRAYS_OVERLAP( split(abc,','), split('1,2',','));
其中包含虚拟数据:
select * from values
('1'),
('0,4'),
('0,1,5')
给出:
'ABC' | ABC |
---|---|
abc | 1 |
abc | 0,1,5 |