有沒有辦法通過輸入引數值來選擇在 MS Access 中使用 SQL 合并哪個表?
假設我有 3 個表:用戶、2021 和 2022。
我的任何查詢是:
SELECT
Users.code, 2021.consumption
FROM
Users
INNER JOIN
2021 ON Users.code = 2021.code
WHERE
(((Users.code) = [Insert the user code]))
我得到“輸入引數值”視窗來過濾我想檢查的代碼,但我想得到同樣的選擇其他表(2022)
uj5u.com熱心網友回復:
據我所知,您不能將表名作為引數,但您可以執行以下操作:
SELECT
U.code, Yr.consumption
FROM
Users as U
INNER JOIN
(select * from [2021] Yr where [Insert Year]=2021
UNION ALL
select * from [2022] Yr where [Insert Year]=2022
) as Yr
ON U.code = Yr.code
WHERE
(U.code = [Insert the user code])
您需要將查詢與現有/新表匹配;或預先創建它們。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/433076.html
上一篇:SQL-如何使用聯合獲取列的總和
