MySQL实现根据最近一周添加最多纪录显示数据

  1. 需求:连表查询最近一周纪录并根据某字段新增后分组,倒叙排列
  2. 展示
    MySQL实现根据最近一周添加最多纪录显示数据_第1张图片
  3. 代码
SELECT
	t.id,
	t.preferential_Category_Name,
	l.laws_sign,
	COUNT( 0 ) AS total 
FROM
	preferential_policies_sort t
	LEFT JOIN preferential_policie l ON l.secondcategory_id = t.id 
WHERE
	laws_sign = t.update_time BETWEEN CURRENT_DATE - 7 
	AND SYSDATE( ) 
GROUP BY
	t.id,
	t.preferential_category_name,
	l.laws_sign 
ORDER BY
	total DESC
	

你可能感兴趣的:(JAVA)