b*****e 发帖数: 474 | 1 if different names have different ids, would this work:
select StockName, max(price)
from StockData
group by StockID, StockName
select D1.*
from StockData as D1, (select StockID, max(price)
from StockData group by StockID) as D2
where D1.StockID = D2.StockID
AND D1.price < ...
有 |
|
f*****g 发帖数: 15860 | 2 SELECT * FROM STOCKDATA S,
(select stockid, max(price)
from StockData
group by StockID) AS M
WHERE S.stockid = M.stockid
有 |
|
|
|
|
|
A*******y 发帖数: 11148 | 7 写了段SQL语法,数据库是很多股票月度performance
如果希望挑出每只股票价格最高的纪录的话,比如
select max(price)
from StockData
group by StockID
这样一来,如果我想加入其他字段,比如StockName,系统就会说即不在Group by又没有
aggregate。。。请问有什么解决办法吗?
还有,如果我想按照价格挑选所有字段,有什么办法不用手工输入所有字断名吗?
谢谢大家 |
|
a*******t 发帖数: 891 | 8 fryking's method should work, probably the correct way also.
but usually I just cheat and use
select max(stockName) as StockName, max(price) as MaxPrice
from StockData
where price is between 10 and 20 --your 2nd question
group by StockID
有 |
|