有4个tables:a、b、c、d
有一个id:4(输入)
查询应该打印出id出现在表中的次数
前任:
in table A id:4 occurs 5 times
in table B id:4 occurs 7 times
in table C id:4 occurs 3 times
in table D id:4 occurs 1 times
输出:
Table name No of occurence
A 5
B 7
C 3
D 1
3条答案
按热度按时间ltqd579y1#
vwoqyblh2#
你可以试试这样的方法:
irtuqstp3#
做那件事
union all
```select 'A' as Name, count() as occurence from tablea where id = ?
union all
select 'B' as Name, count() as occurence from tableb where id = ?
union all
select 'C' as Name, count() as occurence from tablec where id = ?
union all
select 'D' as Name, count() as occurence from tabled where id = ?