我在 MySQL 中有 6 个表,它们是这样映射的。 (泛化/特化)
1.Expense
2.Administrative Expense
3.Vehicle Expense
4.Machine Expense
5.Salaries
6.Purchases
费用是父类(super class),其他是子类。 Expense 表的主键“expenseId”被引用,并且是其他表的主键。 ID的格式为“EXP0001”。
我想检查给定的 ID(例如“EXP00010”)是否是管理费用或车辆费用或类似费用。在这种情况下要使用什么查询?我需要找到包含给定值的子类关系的名称。
提前致谢!
最佳答案
返回行时选择表名作为常量:
select * from (
select 'Expense', * from expense
union
select 'Administrative Expense', * from Administrative_Expense
union
-- etc for all tables
) all
where expenseId = ? -- or join etc
关于java - 获取记录存在的mysql表名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25740149/