表格:
autn itcode date qty phstock
----------------------------------------
1 10 1/1 1
2 5 2/2 1
3 6 1/1 5
4 10 2/1 5
5 9 1/1 5
6 10 3/1 1 5
7 5 5/1 2
8 5 6/1 5
9 10 5/5 1
10 5 7/1 2
11 10 7/2 5 2
12 10 7/8 2
如何输出如下:
autn itcode date qty phstock
--------------------------------
11 10 7/2 5 2
12 10 7/8 2
提示:我只想记录我最后一次输入成人版本的phstock'![在此处输入图片说明] [1]
答案 0 :(得分:1)
这将返回设置了phstock
的最新行之后的所有行:
select *
from YourTable
where date >=
(
select max(date)
from YourTable
where phstock is not null
)
答案 1 :(得分:0)
select *
from YourTable x
where x.date = (
select max(y.date) from Yourtable y
)
如果我找到了你,那么你只想要一个特定的'phstock'。
select * from YourTable c
where x.date = (
select max(y.date) from Yourtable y where y.phstock = <YourPhStockHere>
)
and x.phstock = <YourPhStockHere>