簡體   English   中英

如何從 SQL 中的所有表中獲取多列值

[英]How to get multiple columns value from all the tables in SQL

我正在嘗試從所有表中獲取列值,我有一些包含 group_name 和 date 的表,到目前為止,我只需要所有表中的 group_name 和 date 值

表格1

在此處輸入圖像描述

表 2

在此處輸入圖像描述

這是我的查詢(查詢沒有返回任何內容)

select table_name
from information_schema.columns
where column_name = 'group_name' AND column_name = 'date'

所以 output 應該是這樣的

在此處輸入圖像描述

注意:我不想指定表名,因為會有很多表。 我只展示了兩個,表名是動態的,可以從前端刪除或創建

將前端創建的表的名稱存儲在另一個名為 user_tables 的表中。 利用:

SELECT table_name from user_tables

這將返回一個表名列表["table1", "table2", "table3"] 然后從表名列表中動態生成 sql:

SELECT group_name, date FROM table1
UNION
SELECT group_name, date FROM table2
UNION
SELECT group_name, date FROM table3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM