我知道我可以这样做来从某个表中获取列名:
SELECT
COLUMN_NAME
FROM ALL_TAB_COLS
WHERE TABLE_NAME = 'MY_TABLE'
但是如果我想做这样的事情(比特的伪代码)怎么办:
WITH
SUB1 AS (SELECT COLUMN_1, COLUMN_2 FROM SOME_TABLE1)
SUB2 AS (SELECT COLUMN_1, COLUMN_2 FROM SOME_TABLE2)
RESULTS AS
(SELECT COLUMN_NAME
FROM SUB1
INNER JOIN SUB2 ON SUB1.COLUMN_NAME = SUB2.COLUMN_NAME)
SELECT * FROM RESULTS
这样的事情可能吗?
答案 0 :(得分:1)
如果您有列名的外部列表,则与表列名称进行比较
我建议我在条款
中的位置 SELECT
COLUMN_NAME
FROM ALL_TAB_COLS
WHERE TABLE_NAME = 'MY_TABLE'
AND COLUMN_NAME in ('colname1,' 'colname2' .... )
或不用于反向
答案 1 :(得分:1)
您可以查询information_schema.COLUMNS以获取列名并在表之间进行比较。
Select distinct column_name, table_name
from information_schema.COLUMNS
where table_name in('table1','table2')
and column_name = 'column_name'
答案 2 :(得分:0)
我登陆该页面时正在寻找的解决方案称为“列子查询”。希望对您有所帮助。
选择t1.column1,t1.column2,t2.column1,t2.column2
从some_table1 AS t1中读取
INNER JOIN some_table2 AS t2
打开t1.column1 = t2.column1
t2.column1 =“ column1”;
我对此感到困惑,并在这里找到了解决方案:
https://www.geeksengine.com/database/subquery/return-a-list-of-values.php