SELECTR.* fromTrans_flow R, (SELECTOrder_no,MAX(Status_time) asStatus_time fromTrans_flowGROUP byorder_no) SWHERER.order_no=S.order_no andR.status_time=S.status_timeORDER byR.status_timeDESC SELECTA.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 fromAccount_log aJOIN(SELECTB.*,MAX(ID) fromAccount BGROUP byb.mem_no) C onDate_add (A.create_time, INTERVAL7 Day)<Now () andA. ' Mem_no '=C.mem_noORDER bya.IDdesc
Workaround:
The structure is as follows:
type name guest date
1 aa sa 20131101
1 bb dsf 20131102
1 aa wew 20131103
I want to group by name, in descending order of date, and I want the result as follows:
type name guest date
1 aa wew 20131103
1 bb DSF 20131102
select r.* from tab R, ( Select Name, max (date) From the tab group by name) S
where R.name=s.name and R.date=s . Date
order by r.date desc
MySQL Remove duplicate query SQL statement basic idea