gpt4 book ai didi

mysql - 在mysql中按季度显示数据库中的记录

转载 作者:行者123 更新时间:2023-11-29 23:11:24 25 4
gpt4 key购买 nike

我有一个名为 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    |+----------+-----------+------------+--------------+

Now I want to display all the data by quarter base on its date. Let's say I want to display all the records who belong to 1st Quarter like this:

+----------+-----------+------------+--------------+| total_id | nca_total | nca_date   | account_type |+----------+-----------+------------+--------------+|       13 | 10450     | 2015-01-21 | DBP-TRUST    ||       14 | 5000      | 2015-02-05 | DBP-TRUST    |+----------+-----------+------------+--------------+

This date belongs to the 1st quarter of the year (Jan, Feb, March). I only have this query to select the date and return its quarter number as:

SELECT QUARTER('2015-01-11');       /* returns 1 */

如何组合该查询以按季度显示所有记录?有人可以帮忙吗?谢谢。

最佳答案

select * 
from nca_totals
where QUARTER(nca_date) = 1

关于mysql - 在mysql中按季度显示数据库中的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28064095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com