开发者

ignore some values in insert into select from sql stament

开发者 https://www.devze.com 2022-12-23 15:02 出处:网络
Sup开发者_如何学Gopose that I have a Table Symbols(Symbol, Value) and a Table SymbolValues (Symbol, Value) which contains a list of values for the symbol.

Sup开发者_如何学Gopose that I have a Table Symbols(Symbol, Value) and a Table SymbolValues (Symbol, Value) which contains a list of values for the symbol. How to choose maximum values fromt he SymbolValues table and insert into Symbols table. For Example, The SymbolValues Table has following values

A 1
A 2
A 3
B 6
B 7

Then only A 3 and B 7 should be inserted in the Symbols table.

Is this possible using insert into select statement.

Thanks


Something like this:

insert into symbols(symbol,value)
  (select symbol, max(value) from symbolvalues group by symbol);


You could modify your select query to be something like:

SELECT v.symbol, v.value
FROM SymbolValues v
WHERE NOT EXISTS (SELECT * FROM SymbolValues v2 WHERE v2.symbol = v.symbol AND v2.value > v.value)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号