---MySQL分区SQL函数,取第一条(等价oracle的rownum()over())
SELECT SUBSTRING_INDEX( GROUP_CONCAT(store_in_time ORDER BY take_out_time DESC SEPARATOR '_'),'_',1) store_in_time
,SUBSTRING_INDEX( GROUP_CONCAT(store_in_by ORDER BY take_out_time DESC SEPARATOR '_'),'_',1) store_in_by
,SUBSTRING_INDEX( GROUP_CONCAT(take_out_time ORDER BY take_out_time DESC SEPARATOR '_'),'_',1) take_out_time
,SUBSTRING_INDEX( GROUP_CONCAT(take_out_by ORDER BY take_out_time DESC SEPARATOR '_'),'_',1) take_out_by
,csmb_code
FROM (
SELECT csmb_code,store_in_by,store_in_time,take_out_by,take_out_time FROM csmb_high_history where 1=1 ORDER BY take_out_time
)b GROUP BY csmb_code
-------------------MySQL生成序号@row_number:=@row_number+1
SELECT csmb_code,change_time,(@row_number:=@row_number+1) AS row_number FROM csmb_high_state_change a,(SELECT (@row_number:=0))b ORDER BY change_time desc;