PL / SQL - 获取最近一个月和总销售额

时间:2015-10-16 15:36:12

标签: oracle plsql oracle11g

假设您有这个表结构:

enter image description here

如何查询此数据以便提供最近一个月(4)和总销售额(11000)?

2 个答案:

答案 0 :(得分:2)

简单max + sum即可:

select max(month),
       sum(total_sales)
  from table_name

答案 1 :(得分:2)

如果您只想最近一个月使用简单的最大值

-- this should return 4 and 11000
select max(month),sum(total_sales) from table1;

如果表中有其他列,则可以包含这些列(例如今年的total_sales ...)