Solved

SQL Select Statement

Posted on 2008-11-03
3
202 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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