回答

收藏

mysql连接同一张表不同的结果集

技术问答 技术问答 254 人阅读 | 0 人回复 | 2023-09-12

我想将来自同一张表的不同结果合并为一个大结果。% [0 D  U) c  R/ m: z; D3 ~
SELECT host_name,stats_avgcpu,stats_avgmem,stats_avgswap,stats_avgiowait     FROM sar_stats,sar_hosts,sar_appgroups,sar_environments    WHERE stats_host = host_id    AND host_environment = env_id    AND env_name = 'Staging 2'    AND host_appgroup = group_id    AND group_name = 'Pervasive'    AND DATE(stats_report_time) =  DATE_SUB(curdate(),INTERVAL 1 DAY)SELECT AVG(stats_avgcpu),AVG(stats_avgmem),AVG(stats_avgswap),AVG(stats_avgiowait) FROM sar_stats  WHERE  stats_id = "stat_id of the first query" and DATE(stats_report_time)    BETWEEN DATE_SUB(curdate(),INTERVAL 8 DAY) and DATE_SUB(curdate(),INTERVAL 1 DAY)SELECT AVG(stats_avgcpu),AVG(stats_avgmem),AVG(stats_avgswap),AVG(stats_avgiowait) FROM sar_stats  WHERE  stats_id = "stat_id of the first query" and DATE(stats_report_time)    BETWEEN DATE_SUB(curdate(),INTERVAL 31 DAY) and DATE_SUB(curdate(),INTERVAL 1 DAY)所需的输出将相似…
9 Z: D2 Q& B8 ^, @! mhost_name|stats_avgcpu|stats_avgmem|stats_avgswap|stats_avgiowait|7daycpuavg|7daymemavg|7dayswapavg|7dayiowaitavg|30daycpuavg|30daymemavg|....etc               
# u# l# p8 u- e/ M! W0 S    解决方案:
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则