数据库有表如下:
2015-10-1-table/2015-10-2-table……2015-10-31-table
共31个表。每个表结构一样,都有id,都有code,都有money。现在要查出每个表里,每个money的最高值对应的code。
sql怎没写?
2015-10-1-table/2015-10-2-table……2015-10-31-table
共31个表。每个表结构一样,都有id,都有code,都有money。现在要查出每个表里,每个money的最高值对应的code。
sql怎没写?
解决方案 »
- How to use MySQL Cluster API in windows
- mysql添加trigger后无法插入数据的问题
- 用VC通过DLL包连接MySQL,执行存储过程后,再执行其他查询无效?
- 关于SQL执行时间的问题
- linux+mysql正常用了半年多了,但今天因为停电,重新启动后mysql就起不来了
- sql语句?
- 在线等:在Mysql中关于字符串转换日期
- 问:delphi是否支持mysql?
- mysql中 KEY boardbbs1 (BoardID)的用法和含义
- postgresql 高手请进!有难题等待你解决!(数据导入/断开连接)
- 小白求问~~望帮解答
- 使用SQLyog工具连接数据库出现10060报错
union all
(select '2015-10-2-table' as k,`money`,`code` from `2015-10-2-table` order by `money` desc limit 1)
union all
(select '2015-10-3-table' as k,`money`,`code` from `2015-10-3-table` order by `money` desc limit 1)
union all
...
union all
(select '2015-10-31-table' as k,`money`,`code` from `2015-10-31-table` order by `money` desc limit 1)
FROM 2015-10-1-table
GROUP BY id,code
UNION ALL
SELECT id,code,max(money)
FROM 2015-10-2-table
GROUP BY id,code
.....
(select '2015-10-1-table' as k,`money`,`code` from `2015-10-1-table` order by `money` desc limit 1)
union all
(select '2015-10-2-table' as k,`money`,`code` from `2015-10-2-table` order by `money` desc limit 1)
union all
(select '2015-10-3-table' as k,`money`,`code` from `2015-10-3-table` order by `money` desc limit 1)
union all
...
union all
(select '2015-10-31-table' as k,`money`,`code` from `2015-10-31-table` order by `money` desc limit 1)