我有5张桌子。
给定折扣价值,我想查找折扣价值是出现在哪些表格及其对应的userids
中。
例如:让我们说12% discount
。我想检查12% exists
在哪些表格中(例如,表格2,表格3)以及他们的userid
注意:折扣价值在给定表格中仅出现一次(唯一折扣)
有人可以帮助我:)
表
table1(userid,discount)
table2(userid,discount)
table3(userid,discount)
table4(userid,discount)
table5(userid,discount)
答案 0 :(得分:0)
Select * from (select userid,discount from table1
union All
select userid,discount from table2
union All
select userid,discount from table3
union All
select userid,discount from table4
union All
select userid,discount from table5
) a where discount = 12
希望这个人能帮助你找到答案。
答案 1 :(得分:0)
尝试此查询: -
Select * from
(
select userid,discount from table1
union
select userid,discount from table2
union
select userid,discount from table3
union
select userid,discount from table4
union
select userid,discount from table5
)
dis where dis.discount = 12