各位高手们,我现在想问一个问题,在我的数据库中有一张用与存放图书入库的表,里面的字段有图书入库时间(book_in_date),入库数量(book_in_num),还有入库价格(book_in_price)等,现在就是说我如果想要得知各种图书的最近进货价是多少,这个要怎么实现呢?

解决方案 »

  1.   

    这个表里肯定有一个字段是图书编码或者id什么的吧,假设是idselect * from tablename t1
    where not exists (select 1 from tablename where id = t1.id and book_in_date > t1.book_in_date)
      

  2.   

    假设图书编号为book_id
    select a.book_id , b.book_in_date , a.book_in_price as 最近进货价 from TB a, 
    (select book_id , max(book_in_date) as book_in_date from TB group by book_id) b
    where a.book_id = b.book_id and a.book_in_date = b.book_in_date
      

  3.   

    入库保存时则把最后进价UPDATE到图书资料表里对应的图书上就可以了.很简单的
      

  4.   

    在图书资料表里增加一个最后进价的字段,就UPDATE到这个上.
      

  5.   

    select bookname,book_in_price,book_in_date,bookid
    from book
    where (getdate()-book_in_date)<=天数
    group by bookid
      

  6.   

    这个嘛 很简单朋友!!
      你这样做!
    select book_in_price
    from 表
    where book_in_price=(select max(book_in_price) from 表)   
      应该可以实现您所说的!