sql server - How to search max value from group in sql -


i learning sql, have question.

-i have table name tabl

-a variable :ccname has value "bottle"

the table follows:

   +----------+---------+-------+--------+    | name     |  price  |  qty  |  code  |    +----------+---------+-------+--------+     | rope     |   3.6   |   35  |   236  |    | chain    |   2.8   |   15  |   237  |    | paper    |   1.6   |   45  |   124  |    | bottle   |   4.5   |   41  |   478  |    | bottle   |   1.8   |   12  |   123  |     | computer | 1450.75 |   71  |   784  |    | spoon    |   0.7   |   10  |   412  |    | bottle   |   1.3   |   15  |   781  |    | rope     |   0.9   |   14  |   965  |    +----------+---------+-------+--------+ 

now want find code variable :ccname higher quantity! translated this:

select code tabl group :ccname qty=max(qty) 

in perfect world turn result 478. in sql world should write in order 478?

try this

select code tablename qty = (select max(qty) tablname name = :ccname) 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -