MySQL常用查询
Posted 知其黑、受其白
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL常用查询相关的知识,希望对你有一定的参考价值。
mysql 根据两个字段分组,根据两个字段排序
获取年和季度分组,并设置年排序和季度排序。
SELECT year, quarter FROM report
WHERE FIND_IN_SET(`quarter`, 'Q1,Q2,Q3,Q4')
GROUP BY `year`, `quarter`
ORDER BY `year` DESC, `quarter` DESC
多 where 应用
select `create_time`,`field_id`,`field`, `name`, `form_type`, `order_id`, `order_list`, `is_show`
from `hhir_crm_admin_field`
where (`types` = 'crm_upload_quarter' and `valid` = 1 and `is_filter` = 0)
ORDER BY `order_id` ASC,`create_time` DESC
MySQL 根据统计 ID 出现次数和根据年度、季度分组
SELECT count(fund_id) AS count_fund_id, year, quarter
FROM report
GROUP BY fund_id, year, quarter
MySQL 分组排序过滤
未过滤的数据
SELECT year, quarter FROM report
GROUP BY `year`, `quarter`
ORDER BY `year` DESC, `quarter` DESC
过滤的数据
SELECT year, quarter FROM report
GROUP BY `year`, `quarter`
HAVING `quarter` NOT IN ('Q1', 'Q2', 'Q3', 'Q4')
AND `quarter` != ''
ORDER BY `year` DESC, `quarter` DESC
以上是关于MySQL常用查询的主要内容,如果未能解决你的问题,请参考以下文章