Solved

SQL Select Statement

Posted on 2008-11-03
3
203 Views
Last Modified: 2010-03-20
Hi,

I have a table which contains prices for assets. The asset is not priced everday. All I need to do is get the latest price for all assets held in the table..?

Table example:

Asset                         Price Date  (UK Dates)                Price
A                                03/11/2008                                  4
A                                01/01/2008                                  5
A                                01/07/2007                                  6
B                                01/02/2008                                  7  
B                                01/01/2005                                  7
B                                01/07/2004                                  8  
C                                01/07/2004                                  18  

The SQL should return...
A                                03/11/2008                                  4
B                                01/02/2008                                  7  
C                                01/07/2004                                  18  

Thanks in advance...
0
Comment
Question by:ISC
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22866042
you mean:
SELECT t.*
  FROM yourtable t
 WHERE t.Price_Date = (SELECT MAX(i.price_date) FROM yourtable i WHERE i.Asset = t.Asset )

Open in new window

0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 22866044
select distinct asset,price,date from table t1order by price desc.
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 22866052
sorry mine is wrong.ignore that one.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question