如何通过单一查询获得当年和上一年的卢比总和?

时间:2014-03-02 10:38:32

标签: mysql

我想选择当前年度卢比和前一年卢比的总和。以下是我的表格字段:

   |Material_Number|Material_name|Date      |Rupees   |
   |1              |abc          |2014-02-01|1.20,000 |
   |1              |abc          |2014-02-02|50,000   |
   |1              |abc          |2013-05-05|1,50,000 |
   |5              |pqr          |2012-01-05|20,000   |
   |2              |xyz          |2013-05-04|10,000   |
   |2              |xyz          |2014-01-04|10,100   |
   ----------------------------------------------------

我想显示当年和上一年的卢比的物质明智总和。以下是我想要的表结构:

  ---------------------------------------------------
  |Previous_Year_sum| Material_name|Current Year_sum|
  --------------------------------------------------- 
  |1,20,000         | abc          | 1,50,000       |
  ---------------------------------------------------

2 个答案:

答案 0 :(得分:0)

请尝试使用SUM()条件<{1}}

CASE

See Demo Here

答案 1 :(得分:0)

select YEAR(Date) as year , SUM(rupees), material_name from test group by material_name, year;