本文介绍了日期列的SQL计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含一组列的表,其中一个是Date列.
I have a table that containts a set of columns one of it is a Date column.
我需要计算该列的值引用同一月份的次数.并返回如果一个月的总和大于3.
I need to count how many occurrences of the values of that column refer to the same month. And return if for one month, that count sums more than 3.
例如:
____________________
| DATE | .... |
---------------------
1998-09-02
1998-09-03
1998-10-03
1998-10-04
这必须不返回任何值.因为它没有必要的重复次数.
This must return no value. Because it doesn't have the necessary number of repetitions.
但这确实做到了:
____________________
| DATE | .... |
---------------------
1998-09-02
1998-09-03
1998-09-12
1998-09-14
1998-10-02
1998-11-21
11月.
用于Oracle数据库.
Is for an Oracle DB.
推荐答案
SELECT
COUNT(date)
, TRUNC(DATE,'MON')
FROM TABLE
GROUP BY TRUNC(DATE,'MON')
HAVING COUNT(DATE) > 3
这篇关于日期列的SQL计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!