---
title: "sql 统计类语句"
author: "stevenjohn"
date: "2014-03-17T16:59:17Z"
tags: []
categories: ["数据库"]
slug: "sql"
draft: false
lastmod: "2014-03-17T18:13:08Z"
id: 2032399
url: "https://stevenjohn.iteye.com/blog/2032399"
---

1、统计每月的成交量，按照逆序排序(2013年以来的每月销量，oracle实现)
 select to_char(t.payment_time,'yyyy-MM'),count(t.id) as 笔数,sum(t.payment_amount) as 月总金额 from business_journal t where t.payment_type='11' and t.err_code='00' and 
to_date(to_char(t.payment_time,'yyyy-MM-dd'),'yyyy-MM-dd')>to_date('2012-12-31','yyyy-MM-dd') group by to_char(t.payment_time,'yyyy-MM') having count(t.id)>0
 order by to_char(t.payment_time,'yyyy-MM') desc ;