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
我应该在查询中更改什么?
解决方案
推荐阅读
- android - RecyclerView中的ViewPager:Viewpager拦截父View的点击
- python - 熊猫根据条件创建列
- redux-form - 即使使用 initialValues 设置,React Redux Form 也无法通过所需的验证
- python-2.7 - HTTP 响应代码错误地出现在实际为 200 的位置
- javascript - SCSS data-theme="dark" 变量不加载
- r - 基于列中的多个值进行过滤
- azure - Get-AzADServicePrincipal ApplicationId 在 powershell-pipeline 中为空,但在 shell 上工作
- jquery - 使用 jQuery .slideToggle() 和 display: grid;
- r - R - 找到所有可能的成对日期重叠
- mathematical-optimization - 多维求根的数值算法