我如何获取数据库中的最新记录

时间:2019-05-13 05:18:20

标签: mysql

我需要从deli_order表中获取最新记录。我当前的桌子是这样的

order_code       |      code    |     create_time      | status
1914311385030918    nebula74920   2019-05-10 17:12:30      Fail
1914311385030918    nebula74920   2019-05-12 04:16:30      Fail
1914311385030918    nebula74920   2019-05-13 10:01:30      Success

有3条记录具有相同的order_code和code,但状态不同。

我只需要生成成功的交易。以下是我的查询

select 
    a.order_code as 'TRANSACTION ID',
    max(a.create_time) as 'TRANSACTION DATE',
    a.code as 'ORDER ID',
    case
        when a.status='8' then 'Failed'
        when a.status='6' then 'Completed'
        when a.status='5' then 'To be reviewed'
        when a.status='3' then 'To be accepted'
        when a.status='2' then 'To be accepted'
    else 'N/A'
    end as 'BLUTAB STATUS',
    b.lp_sign_time as 'PICK UP TIME'   
 from deli_order a
 left join pg_send_package b on a.code = b.code and a.order_code = b.order_code
 where date_format(a.plat_create_time, '%Y-%m') = '2019-05'
 group by a.order_code, a.code;

我希望获得具有成功状态的交易。但这就是我得到的

order_code       |      code    |     create_time      | status
1914311385030918    nebula74920    2019-05-13 10:01:30   Fail

我应该更改查询什么内容?

0 个答案:

没有答案