需求:某条件下获得条码(我已经指定好了'1901000005/1','1901000006/1'条码),条码的最近时间的相应记录?
我的实现步骤:
一,获得条码,和条码的最近时间(以下SQL语句可以实现)Select itemcode ,max(fscandate)as 'thelasttime'
from z_kuka_cjbill
Where itemcode  In( '1901000005/1','1901000006/1')
group by itemcode得到以下结果集:
itemcode        thelasttime
1901000005/1     2009-01-09 07:03:00.000
1901000006/1     2009-01-09 07:03:00.000
二,以条码、条码的最近时间为条件,查询表z_kuka_cjbill中的其它记录(如何写SQL语句,存储过程我已经写好,在
http://topic.csdn.net/u/20090901/08/a606a395-db35-470d-985a-3502eab8ba48.html中,只要把#Temp取个别名就好了。)

解决方案 »

  1.   


    Select itemcode ,max(fscandate)as 'thelasttime'
    from z_kuka_cjbill
    Where itemcode  In( '1901000005/1','1901000006/1')
    group by itemcode其实我的需求很简单,就是想把以上得到的结果集。通过以下SQL语句。再重新得到一个新的结果集。Select * From z_kuka_cjbill a Inner Join (
    Select itemcode ,max(fscandate)as 'thelasttime'
    from z_kuka_cjbill
    Where itemcode  In( '1901000005/1','1901000006/1')
    group by itemcode)b
    On a.itemcode=b.itemcode And a.fscandate=b.thelasttime请大家把我需求和以上两句SQL语句结合起来想想,我是否写对了。(百分之九九是正确的)