我有一张名为nca_totals的表。
Table: nca_totals +----------+-----------+------------+--------------+ | total_id | nca_total | nca_date | account_type | +----------+-----------+------------+--------------+ | 13 | 10450 | 2015-01-21 | DBP-TRUST | | 14 | 5000 | 2015-02-05 | DBP-TRUST | | 15 | 7000 | 2015-04-02 | DBP-TRUST | | 16 | 4000 | 2015-05-02 | DBP-TRUST | +----------+-----------+------------+--------------+
现在我希望按日期按季度显示所有数据。让我们说我想要显示属于第一季度的所有记录,如下所示:
+----------+-----------+------------+--------------+ | total_id | nca_total | nca_date | account_type | +----------+-----------+------------+--------------+ | 13 | 10450 | 2015-01-21 | DBP-TRUST | | 14 | 5000 | 2015-02-05 | DBP-TRUST | +----------+-----------+------------+--------------+
此日期属于一年的第一季度(1月,2月,3月)。我只有这个查询来选择日期并将其季度数字返回为:
SELECT QUARTER('2015-01-11'); /* returns 1 */
如何组合该查询以按季度显示所有记录?有人可以帮忙吗?感谢。
答案 0 :(得分:0)
select *
from nca_totals
where QUARTER(nca_date) = 1
答案 1 :(得分:0)
SELECT
CEIL(MONTH(`nca_date`) / 3) AS `quarter`
FROM `nca_totals`;