SQL value at min query without join -


quite have solve following problem. suppose have 3 columns: col a, col b, col c.

col contain date need group on. col b contains value need find minimum each group in col a. , col c contains data find minimum occurred, pull value col c corresponding min in col b.

i commonly solve problem, writing join statement. know better solution, without join? problem seem common me image make sense create dedicated sql command. finding value of function @ point of minimum (from math point of view)

regards,

update.

i apologize not posting example of mean. here table:

location            quantity    street new york            2            broad new york            3            main pittsburgh          1            grove pittsburgh          5            school austin              7            hayes austin              2            barn 

i group "location" , choose min in "quantity" each group. find "street" corresponding each min value.

here how final output should like:

 location           quantity    street  austin             2           barn  new york           2           broad  pittsburgh         1           grove 

and here how accomplish ( believe long , there should dedicated sql function it)

select thefunction.location, quantity, street   [analysisdatabase].[dbo].[valueatmin] thefunction  inner join   (select [location], min([quantity]) minvalue [analysisdatabase].[dbo].[valueatmin] group [location]) xvalue  on thefunction.location = xvalue.location , xvalue.minvalue = thefunction.quantity 

this works dataset in mysql:

select location, quantity, street   tempso c quantity = (select min(quantity)   tempso b   c.location = b.location) order location 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -