Hi Friends,
my table is:
create table tab
(
ref_group,
product,
qty
)
insert into tab(ref_group,product,qty)
values ('Milk Produtcs','Curd','25')
insert into tab(ref_group,product,qty)
values ('Milk Produtcs','Butter','05')
My expecting O/P:
groupProduct product sales free
Milk Products Butter 0 05
here i wanna show lowest product value from group how to make a code?

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jan 21, 2014, 10:36 PM EST
I dont know the calculation for free & sales, still i can assume & give you the solution,
select top 1 ref_group as 'Group Product', product as 'Product', '0' as 'sales', qty as 'free' from tab
order by cast(qty as int) asc
Rocky RockyRank #7,391 · 242 reputationPosted Jan 21, 2014, 10:48 PM EST
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jan 21, 2014, 10:50 PM EST
How do you calculate sales & free values?
Rocky RockyRank #7,391 · 242 reputationPosted Jan 21, 2014, 10:57 PM EST
The highest value in group item is sales remaining items (i.e
Group Product Sales Free
Milk Products Curd 25 0
These already done my code
My need Is
bill Group Product Sales Free
24 Milk Products Butter 0 05
I.e to neglect the highest value in group display lowest like above
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Jan 21, 2014, 11:24 PM EST
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Jan 21, 2014, 11:25 PM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 22, 2014, 2:38 AM EST
hi,
agree with Biswa answer but where can we get the sale column data?
and also other problem with the query is there are different name for product
if you sale data is always 0 then
try...
select A.ref_group,p.product, 0 as sales,free from (
select ref_group, min(qty) as free
from tab
group by ref_group) A
inner join tab p on p.ref_group = a.ref_group and p.qty = a.free
hope this will help you.