- MySQL分组统计并排序
SELECT
DATE_FORMAT( Time1, '%Y-%m' ) AS new_date, # 格式化取时间的Ym
field2,
count(DISTINCT(field3)) AS sku_count, #字段去重后统计数量
COUNT( 1 ) #数据的数量(数自己)
FROM
db1.b_store_order
GROUP BY #按new_date,field2分组
new_date,
field2
ORDER BY
new_date DESC #按new_date倒序
网友评论