我应该编写一个查询,显示2010年每个月的降利总额。
到目前为止,我有一个查询显示2010年降序的总利润,我有一个可以提取每个月的查询,但我似乎无法连接这两个。
select (SalesPrice - AcquisitionPrice) profit, datesold
from Transaction
where DateSold >= '10-jan-01' and DateSold <= '10-dec-31';
和
select to_char(datesold, 'mon')
from transaction
group by to_char(datesold, 'mon')
答案 0 :(得分:0)
Oracle查询:
SELECT EXTRACT( MONTH FROM datesold ) AS mnth,
SUM( SalesPrice - AcquisitionPrice ) AS profit
FROM Transaction
WHERE EXTRACT( YEAR FROM datesold ) = 2010
GROUP BY EXTRACT( MONTH FROM datesold )
ORDER BY EXTRACT( MONTH FROM datesold ) DESC
MySQL和Oracle查询:
{{1}}