Solved

SQL Select Statement

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now