sql 对某个字段去重,并按照另外一个字段排序

需求: 实现对表中的单据字段去重,并且按照生成日期字段排序。
使用:
1 select distinct bill from table where xxxx
order by bill ;
distinct bill 字段,不能按照其他字段排序。

  1. select bill ,date from table where xxx
    order by date desc;
    未实现bill 字段去重
    使用 group by 实现去重

  2. select bill,max(date) from table
    group by bill order by date desc;
    或者
    select bill from table where xxxxx group by bill
    order by max(date) desc;


版权声明:本文为sophiemantela原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。