答案 0 :(得分:1)
此查询将为您提供每周max
次费用:
SELECT supplier, year, week_of_month, MAX(wom_amt)
FROM table t
GROUP BY supplier, year, week_of_month;
现在,为了将此金额与其余的SUM
进行比较,您可以将此查询包装到外部查询中并计算SUM
,例如:
SELECT a.supplier, a.year, a.week_of_month, a.wom_amt as 'max_amount',
(SELECT SUM(wom_amt) FROM table WHERE supplier = a.supplier AND year = a.year
AND week_of_month = a.week_of_month AND wom_amt != a.wom_amt) as 'other_amounts'
FROM (SELECT supplier, year, week_of_month, MAX(wom_amt)
FROM table t
GROUP BY supplier, year, week_of_month) a;
答案 1 :(得分:-1)