是否可以使用自己的元组作为 JOIN 语句的源?
这是我正在寻找的示例:
SELECT u.id, u.name FROM users u
INNER JOIN {{tupl1},{tupel2},{tupel3},...}
在 SQL Server 2008 中,您使用Table Value Constructor。
declare @T table(ID int)
insert into @T values (1),(2),(3),(4),(5)
select *
from @T as T1
inner join (
values (1, 'Row 1'),
(2, 'Row 2')
) as T2(ID, Col1)
on T1.ID = T2.ID
许多 dbms 平台支持公用表表达式。
with my_own_tuples as (
select 'value1' as column1, 'value2' as column2
union all
select 'value3', 'value4'
union all
select 'value5', 'value6'
)
select column1, column2
from my_other_table
inner join my_own_tuples on (my_own_tuples.column1 = my_other_table.column1);
MySql对具有比较和相等性的元组有一些支持,尽管我正在努力寻找一个明确的参考。
例如:
SELECT *
FROM table1 t1
INNER JOIN table2 t2
ON (t1.Col1, t1.Col2) = (t2.Col1, t2.Col2);
和
SELECT *
FROM table1 t1
WHERE (t1.Col1, t1.Col2) <= ('SomeValue', 1234);