举个栗子,我有一个表金额表,t_money 我需要拿到1年内最高的金额,则
SQL: select max(money) from t_money where 最近一年;
同时,我需要拿到最近一个季度最高的金额
select max(money) from t_money where 最近一季度;
这样子写实在很粗暴,查两次表,如果多个条件,要各种写sql.一点都不优雅。如何只查一次表完成这个效果
select max(money) 最近一年最大,
max(case when 最近一月 then money end ) 最近一月最大
from t_money where 最近一年
select max(money) from t_money where 最近一年
union all
select max(money) from t_money where 最近一季度
类似这样吧,只通过一个 select和where应该没法实现
SELECT t1.yearMax,
t2.quarterMax
FROM
(SELECT max(money) AS yearMax
FROM t_money
WHERE 年 ) t1,
(SELECT max(money) AS quarterMax
FROM t_money
WHERE 季度) t2