美文网首页
mysql语句案例

mysql语句案例

作者: Aedda | 来源:发表于2019-07-25 10:28 被阅读0次
  1. 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倒序

相关文章

网友评论

      本文标题:mysql语句案例

      本文链接:https://www.haomeiwen.com/subject/nlycrctx.html