-4

桌子:

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]

4

2 回答 2

1

这将返回设置的最新行之后的所有行phstock

select  *
from    YourTable
where   date >=
        (
        select  max(date)
        from    YourTable
        where   phstock is not null
        )
于 2012-12-27T10:11:41.580 回答
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>
于 2012-12-27T10:10:31.150 回答