简体   繁体   English

按季度从mySQL调用一组结果的最佳方法是什么?

[英]what is the best way to call a group of results from mySQL by quarter?

I am looking to order a set of results of a mySQL data by quarter. 我正在按季度订购一组mySQL数据的结果。 They have data fields, so I am wondering if I should be doing this in PHP or in the query itself? 它们具有数据字段,所以我想知道应该在PHP还是在查询本身中执行此操作?

if you have date field in the db use it to group with it, 如果您在数据库中有日期字段,请使用该字段进行分组,

like :

group by QUARTER(date)

of course if you want to take in account the years also 当然,如果您也要考虑年份

use 采用

group by YEAR(date) , QUARTER(date)

You can use GROUP BY Clause in mysql query and return results as - 您可以在mysql查询中使用GROUP BY子句,并将结果返回为-

group by Quarter(date)

Where Quarter is a pre-defined function in mysql. 其中Quarter是mysql中的预定义函数。

我会在数据库中执行此操作-查找MySQL函数Quarter(Date)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 考虑到速度和安全性,从MySQL调用数据的最佳方法是什么? - what is the best way to call data from MySQL with speed and security in mind? 将MySQL结果转换为简单数组的最佳方法是什么? - What's the best way to turn MySQL results into simple array? 在PHP中以数组形式获取MySQL查询结果的最佳方法是什么? - What is the best way to get MySQL query results as an array in PHP? 当 sql_mode=only_full_group_by 时,在 mysql 中完成 Group By 工作的最佳方法是什么 - What is the best way to do the job of Group By in mysql when sql_mode=only_full_group_by 从PHP的动作表单中调用函数的最佳方法是什么? - What is the best way to call a function from action form in PHP? 从外部域调用 php 变量的最佳方法是什么? - What's the best way to call php variables from an external domain? 如何对MySQL的结果进行分组 - How to group results from MySQL 使用PHP从MySQL检索表的最佳方法是什么? - What is the best way to retrieve table from MySQL using PHP? 将数组从php传递到MySQL存储过程的最佳方法是什么? - What is the best way to pass an array from php to MySQL stored procedure? 从 mysql 数据库生成和打印数据的最佳方法是什么 - What is the best way to generate & print out data from mysql database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM