Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select distinct MRP.[date],FT.feedtype,round(MRP.rateperkg,3) as Rateperkg from
    K_FS_FeedMrpDetails MRP inner join K_FPS_feedtype FT on FT.sno=MRP.feedtype
    where MRP.[date] between '2013-08-09 00:00:00.000' and '2014-08-25 00:00:00.000' and
    MRP.state = 1  and MRP.rateperkg != 0
    group by ft.feedtype,mrp.rateperkg order by MRP.[date] desc


In my query has same column values feedtype and rateperkg..

Now i want to distinct the these two columns ...how can i do this?


Please help me
Posted
Updated 24-Aug-14 20:20pm
v3
Comments
coded007 25-Aug-14 2:15am    
can you give examples for column values for better understanding ?
[no name] 25-Aug-14 2:17am    
date feedtype Rateperkg
2014-08-20 00:00:00.000 BF Pellet 31.8
2014-08-20 00:00:00.000 BPS 34
2014-08-20 00:00:00.000 Broiler Concentrate 35% 45.9
2014-08-20 00:00:00.000 BS 32.8
2014-08-20 00:00:00.000 Layer Grower - Gold 28.7
2014-08-20 00:00:00.000 LC Phase 1 32.4
2014-08-20 00:00:00.000 LC Phase 2 30.4


2014-08-18 00:00:00.000 BF Pellet 31.8
2014-08-18 00:00:00.000 BPS 34
2014-08-18 00:00:00.000 Broiler Concentrate 35% 45.9
2014-08-18 00:00:00.000 BS 32.8
2014-08-18 00:00:00.000 Layer Grower - Gold 28.7
2014-08-18 00:00:00.000 LC Phase 1 32.4
2014-08-18 00:00:00.000 LC Phase 2 30.4

In this example Feed type and feed rates are same ...Now we want to write the distinct two columns.
_Asif_ 25-Aug-14 4:38am    
Please show us your expected output
[no name] 25-Aug-14 5:00am    
In my above example shows "same rates added but dates are different"
Now My output show only one date feedtype rates

date feedtype Rateperkg
2014-08-18 00:00:00.000 BF Pellet 31.8
2014-08-18 00:00:00.000 BPS 34
2014-08-18 00:00:00.000 Broiler Concentrate 35% 45.9
2014-08-18 00:00:00.000 BS 32.8
2014-08-18 00:00:00.000 Layer Grower - Gold 28.7
2014-08-18 00:00:00.000 LC Phase 1 32.4
2014-08-18 00:00:00.000 LC Phase 2 30.4

1 solution

What date do you want, earliest, latest? I've assumed most recent:

select MAX(MRP.[date]) AS LatestDate,FT.feedtype,round(MRP.rateperkg,3) as Rateperkg from
K_FS_FeedMrpDetails MRP inner join K_FPS_feedtype FT on FT.sno=MRP.feedtype
where MRP.[date] between '2013-08-09 00:00:00.000' and '2014-08-25 00:00:00.000' and
MRP.state = 1 and MRP.rateperkg != 0
group by ft.feedtype,mrp.rateperkg
order by LatestDate desc
 
Share this answer
 

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