Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Databases General > Re: Complex que...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 3092 of 3269
Post > Topic >>

Re: Complex query - PLEASE HELP!

by Thomas Kellerer <FJIFALSDGVAF@[EMAIL PROTECTED] > Feb 2, 2008 at 11:26 AM

S. wrote on 02.02.2008 08:30:
> Hi guys,
> 
> Any ideas with an SQL that will retrieve the expected results?
> 
> Expected Results:
> ==============
> ID      orderdate       customer
> 2       20/02/2007     JONES
> 4       20/06/2007     SMITH
> 6       20/05/2007     BROWN
> 
> The above results are from the following resultset in the database:
> ================================================
> ID      orderdate        customer
> 1	20/01/2007	SMITH
> 2	20/02/2007	JONES
> 3	20/03/2007	BROWN
> 4	20/06/2007	SMITH
> 5	20/12/2007	SMITH
> 6	20/05/2007	BROWN
> 
> I need the:
> - ID of the record
> - the customer name
> - most recent orderdate that occurs for that customer
> - only the records where the orderdate is less than 20/12/2007
> 
> I have been working on this for a while and I have tried the MAX
> function and nested SELECT queries all ending with just frustration.

Hmm. What about:

SELECT *
FROM cust_table ct1
WHERE orderdate = (
      SELECT max(orderdate)
      FROM cust_table ct2
      WHERE ct1.customer = ct2.customer
      AND orderdate < '2007-12-20'
      )
 




 6 Posts in Topic:
Complex query - PLEASE HELP!
"S." <sianea  2008-02-01 23:30:03 
Re: Complex query - PLEASE HELP!
Lennart <Erik.Lennart.  2008-02-02 01:30:03 
Re: Complex query - PLEASE HELP!
Thomas Kellerer <FJIFA  2008-02-02 11:26:24 
Re: Complex query - PLEASE HELP! [Solved]
"S." <sianea  2008-02-02 17:39:01 
Re: Complex query - PLEASE HELP! [Solved]
strawberry <zac.carey@  2008-02-05 14:34:44 
Re: Complex query - PLEASE HELP! [Solved]
Thomas Kellerer <FJIFA  2008-02-06 00:07:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 23:29:23 CDT 2008.