首页 > 代码库 > mysql去除重复查询的SQL语句基本思路
mysql去除重复查询的SQL语句基本思路
SELECT R.* FROM trans_flow R, (SELECT order_no, MAX(status_time) AS status_time FROM trans_flow GROUP BY order_no) S WHERE R.order_no = S.order_no AND R.status_time = S.status_time ORDER BY R.status_time DESC SELECT a.order_no,a.mem_no,c.card_no,c.card_holder,c.bank_name,c.branch_bank_name,a.flag, a.income_type_txt,a.amt,a.create_time FROM account_log a JOIN (SELECT b.*,MAX(id) FROM account b GROUP BY b.mem_no) c ON DATE_ADD(a.create_time, INTERVAL 7 DAY) < NOW() AND a.`mem_no` = c.mem_no ORDER BY a.id DESC
解决思路:
结构如下:
type name guest date
1 aa sa 20131101
1 bb dsf 20131102
1 aa wew 20131103
我想按照name分组,按照date降序排列,希望的结果如下:
type name guest date
1 aa wew 20131103
1 bb dsf 20131102
select R.* from tab R, (select name, max(date) from tab group by name) S
where R.name=S.name and R.date=S.date
order by R.date desc
mysql去除重复查询的SQL语句基本思路
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。