I have the below table and want to get the below results. I basically need a way to get only the most recent date entry from a table of prices.
I have tried this:
select fmc_terminal, fmc_vendor, fmc_prodlnk, fmc_date, fmc_time, fmc_cost
FROM fm_cost
WHERE fm_cost.fmc_date =
(Select max(fmc_date) from fm_cost as f
where fm_cost.fmc_terminal = f.fmc_vendor and
fm_cost.fmc_vendor = f.fmc_vendor
and fm_cost.fmc_prodlnk = f.fmc_prodlnk
GROUP by f.fmc_terminal, f.fmc_vendor, f.fmc_prodlnk)
I am getting no where fast with everything I am trying.
Help please.
fmc_terminal fmc_vendor fmc_date fmc_time fmc_prodlnk fmc_cost
1003 46040025 2/10/2010 18:00 9 1.9925
1003 46040025 2/11/2010 18:00 9 2.0085
1003 46040025 2/12/2010 18:00 9 1.9605
1003 71520016 2/10/2010 12:30 9 1.977
1003 71520016 2/10/2010 18:00 9 1.99
1003 71520016 2/11/2010 18:00 9 2.0015
1003 71520016 2/12/2010 11:30 9 1.9715
1003 71520016 2/12/2010 18:00 9 1.9725
1003 71520016 2/15/2010 10:00 9 1.9725
1004 46520030 2/10/2010 18:00 99 1.9992
1004 46520030 2/11/2010 18:00 99 1.9757
1004 46520030 2/12/2010 18:00 99 1.9689
1004 46520030 2/10/2010 18:00 100 2.2715
1004 46520030 2/11/2010 18:00 100 2.248
1004 46520030 2/12/2010 18:00 100 2.2412
1004 46520030 2/10/2010 18:00 101 2.0682
1004 46520030 2/11/2010 18:00 101 2.0446
1004 46520030 2/12/2010 18:00 101 2.0379
RESULTS
fmc_terminal fmc_vendor fmc_date fmc_time fmc_prodlnk fmc_cost
1003 46040025 2/12/2010 18:00 9 1.9605
1003 71520016 2/15/2010 10:00 9 1.9725
1004 46520030 2/12/2010 18:00 99 1.9689
1004 46520030 2/12/2010 18:00 100 2.2412
1004 46520030 2/12/2010 18:00 101 2.0379
I have tried this:
select fmc_terminal, fmc_vendor, fmc_prodlnk, fmc_date, fmc_time, fmc_cost
FROM fm_cost
WHERE fm_cost.fmc_date =
(Select max(fmc_date) from fm_cost as f
where fm_cost.fmc_terminal = f.fmc_vendor and
fm_cost.fmc_vendor = f.fmc_vendor
and fm_cost.fmc_prodlnk = f.fmc_prodlnk
GROUP by f.fmc_terminal, f.fmc_vendor, f.fmc_prodlnk)
I am getting no where fast with everything I am trying.
Help please.
fmc_terminal fmc_vendor fmc_date fmc_time fmc_prodlnk fmc_cost
1003 46040025 2/10/2010 18:00 9 1.9925
1003 46040025 2/11/2010 18:00 9 2.0085
1003 46040025 2/12/2010 18:00 9 1.9605
1003 71520016 2/10/2010 12:30 9 1.977
1003 71520016 2/10/2010 18:00 9 1.99
1003 71520016 2/11/2010 18:00 9 2.0015
1003 71520016 2/12/2010 11:30 9 1.9715
1003 71520016 2/12/2010 18:00 9 1.9725
1003 71520016 2/15/2010 10:00 9 1.9725
1004 46520030 2/10/2010 18:00 99 1.9992
1004 46520030 2/11/2010 18:00 99 1.9757
1004 46520030 2/12/2010 18:00 99 1.9689
1004 46520030 2/10/2010 18:00 100 2.2715
1004 46520030 2/11/2010 18:00 100 2.248
1004 46520030 2/12/2010 18:00 100 2.2412
1004 46520030 2/10/2010 18:00 101 2.0682
1004 46520030 2/11/2010 18:00 101 2.0446
1004 46520030 2/12/2010 18:00 101 2.0379
RESULTS
fmc_terminal fmc_vendor fmc_date fmc_time fmc_prodlnk fmc_cost
1003 46040025 2/12/2010 18:00 9 1.9605
1003 71520016 2/15/2010 10:00 9 1.9725
1004 46520030 2/12/2010 18:00 99 1.9689
1004 46520030 2/12/2010 18:00 100 2.2412
1004 46520030 2/12/2010 18:00 101 2.0379