有7,8个表, 每个表都有user_id, modify_time这两个字段,通过user_id进行关联, 要求一次性查出全部表的最大modify_time值, 即结果为如下格式:
{ tableA.modify_time == 10,
tableB.modify_time == 11,
tableC.modify_time == 12}
怎么样解?
{ tableA.modify_time == 10,
tableB.modify_time == 11,
tableC.modify_time == 12}
怎么样解?
解决方案
40
竖着写可以这样:
select “{tableA.modify_time==” + MAX(modify_time) + “,” from tableA
union all
select “tableB.modify_time==” + MAX(modify_time) + “,” from tableB
union all
…
…
…
union all
select “tableG.modify_time==” + MAX(modify_time) + “,” from tableG
union all
select “tableH.modify_time==” + MAX(modify_time) + “}” from tableH
select “{tableA.modify_time==” + MAX(modify_time) + “,” from tableA
union all
select “tableB.modify_time==” + MAX(modify_time) + “,” from tableB
union all
…
…
…
union all
select “tableG.modify_time==” + MAX(modify_time) + “,” from tableG
union all
select “tableH.modify_time==” + MAX(modify_time) + “}” from tableH