时间排序,去重复SQL语句

select * from(select distinct barcode,out_date, company_name,company_no,in_date,employee_name,addresser_name,send_address,addresser_phone
    from (SELECT a.barcode,b.company_name,a.company_no,a.in_date,d.employee_name,a.addresser_name,a.send_address,a.addresser_phone,c.out_date FROM post_info a
 Left join express_company_info b on a.company_no = b.express_company_no
 left join post_out_info c on c.barcode=a.barcode
 left join employee_info d on d.employee_job_no=c.employee_no 
 WHERE  a.post_state in ('10','11','12') and a.postal_no = 'BJBSD00001'  ) as tb
 WHERE out_date in(select max(out_date) from (SELECT a.barcode,b.company_name,a.company_no,a.in_date,d.employee_name,a.addresser_name,a.send_address,a.addresser_phone,c.out_date FROM post_info a
 Left join express_company_info b on a.company_no = b.express_company_no
 left join post_out_info c on c.barcode=a.barcode
 left join employee_info d on d.employee_job_no=c.employee_no 
 WHERE  a.post_state in ('10','11','12') and a.postal_no = 'BJBSD00001'  ) as tb group by barcode)
) a order by out_date
posted @ 2011-07-27 16:30  迪卡.凯恩  阅读(669)  评论(1编辑  收藏  举报