Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Dear Friends....


I have a table as shown below.



id name price status

345 AA 5.5 0

346 AA 3.2 0

347 BB 8.9 0

348 AA 6.3 0

349 BB 1.1 0

350 AA 2.1 0

351 BB 3.8 0

352 BB 9.7 0

353 BB 10.0 0

354 BB 12.7 0

355 CC 4.8 0

356 DD 23.7 0

357 DD 24.4 0

358 EE 7.8 0

359 CC 9.2 0

360 CC 4.1 0


This table is the out put just after the insertion process.
I would like to find the third and fourth cheapest(minimum) values of each item and update the corresponding "status" column value to 1 as shown below.




id name price status

345 AA 5.5 1

346 AA 3.2 0

347 BB 8.9 1

348 AA 6.3 1

349 BB 1.1 0

350 AA 2.1 0

351 BB 3.8 0

352 BB 9.7 1

353 BB 10.0 0

354 BB 12.7 0

355 CC 4.8 0

356 DD 23.7 0

357 DD 24.4 0

358 EE 7.8 0

359 CC 9.2 1

360 CC 4.1 0

If anyone has idea about this kindly help me......
Thank You... :)
Posted
Updated 3-Sep-14 18:48pm
v4
Comments
Gihan Liyanage 4-Sep-14 0:39am    
Do you want to find out third and fourth minimum value or, First two minimum values?
SubhashRokzzz 4-Sep-14 0:46am    
third and fourth
Gihan Liyanage 4-Sep-14 1:55am    
Here I build a Query for get first and second minimum values of each group. If you can integrate it for third and fourth. I will try my best to find the correct answer asap. Till that you also can try.

select FinalRate,ItemName FROM
CMStblItems
where (
select count(*) from CMStblItems as f
where f.ItemName = CMStblItems.ItemName and f.FinalRate <= CMStblItems.FinalRate
) <=2;
SubhashRokzzz 4-Sep-14 1:57am    
Sorry! .. I have already this query for first and second..
Gihan Liyanage 4-Sep-14 2:09am    
mm OK , will c for find a one..

1 solution

SQL
DECLARE @Var1 MONEY, @Var2 MONEY, @Var3....


SELECT @Var1 = MIN(Price)
FROM Items


SELECT @Var2 = MIN(Price)
FROM Items
WHERE Price > @Var1


SELECT @Var3 = MIN(Price)
FROM Items
WHERE Price > @Var2

...
 
Share this answer
 
Comments
SubhashRokzzz 4-Sep-14 0:50am    
Hii... Homero Rivera
It won't work... I would like to find the third and fourth minimum values of different Items in the table.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900