MySQL--根據審覈時間排序,查詢最後一次審覈的物品採購記錄
select *
from (select a.CheckDate, b.ProductID, b.Count, b.Price
from tpurchase a, tpurchasedetail b
where a.`Status` in (3, 4)
and a.CheckDate is not null
and a.PurchaseID = b.PurchaseID
order by b.ProductID, a.CheckDate2 desc) m
where (select count(1)
from (select a.CheckDate, b.ProductID, b.Count, b.Price
from tpurchase a, tpurchasedetail b
where a.`Status` in (3, 4)
and a.CheckDate is not null
and a.PurchaseID = b.PurchaseID
order by b.ProductID, a.CheckDate2 desc) s
where m.ProductID = s.productid and m.CheckDate > s.CheckDate) < 1
from (select a.CheckDate, b.ProductID, b.Count, b.Price
from tpurchase a, tpurchasedetail b
where a.`Status` in (3, 4)
and a.CheckDate is not null
and a.PurchaseID = b.PurchaseID
order by b.ProductID, a.CheckDate2 desc) m
where (select count(1)
from (select a.CheckDate, b.ProductID, b.Count, b.Price
from tpurchase a, tpurchasedetail b
where a.`Status` in (3, 4)
and a.CheckDate is not null
and a.PurchaseID = b.PurchaseID
order by b.ProductID, a.CheckDate2 desc) s
where m.ProductID = s.productid and m.CheckDate > s.CheckDate) < 1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.