gpt4 book ai didi

php - 如何选择具有 UNION 结果的表名?

转载 作者:太空宇宙 更新时间:2023-11-03 10:42:03 25 4
gpt4 key购买 nike

这是 UNION 的结果,但我还想知道与每一行关联的源表:

SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;

查询的实际结果是这样的:

city
572
123

但我想要这样的结果:

city tablet_result
572 Customers
123 Suppliers

最佳答案

SELECT City, 'Customers' as tablet_result FROM Customers
UNION
SELECT City, 'Suppliers' as tablet_result FROM Suppliers

关于php - 如何选择具有 UNION 结果的表名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36815446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com