Connecting Tech Pros Worldwide Forums | Help | Site Map

Show the highest and lowest price item sold this month.(SQL)

owz owz is offline
Newbie
 
Join Date: Nov 2006
Posts: 13
#1: Dec 6 '06
Hi again had some more problems, all help welcome. Access 2000, SQL


My problem is as stated in the title. I want 2 display the highest and lowest priced car sold for this month. This is what I have.

Expand|Select|Wrap|Line Numbers
  1.  SELECT  CarSales.Car_Reg,MAX (Purchased_Price) AS Highest_Sale
  2. FROM CarSales
  3. WHERE  Purchased_Price=(SELECT MIN(Purchased_Price)AS Smallest_Sale
  4.                                                                                         FROM CarSales)=
  5.  (((Month([Date_Of_Purchase]))=IIf(Month(Now())=1,12,Month(Now()))))
  6. GROUP BY [CarSales].[Car_Reg] ;
  7.  
Problem with the code is that it displays the highest price 2 the lowest price ordered by date, but they are all in 1 column.

I want it 2 display just the car reg, highest and lowest price all in separate columns.


CarReg Highest Price Lowest Price

cf63gd7 £8,000 £1500



All help welcome.

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,880
#2: Dec 6 '06

re: Show the highest and lowest price item sold this month.(SQL)


Try this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT  CarSales.Car_Reg, MAX (Purchased_Price) AS Highest_Sale, MIN(Purchased_Price) AS Smallest_Sale
  3. FROM CarSales
  4. WHERE (((Month([Date_Of_Purchase]))=IIf(Month(Now())=1,12,Month(Now()))))
  5. GROUP BY [CarSales].[Car_Reg] ;
  6.  
owz owz is offline
Newbie
 
Join Date: Nov 2006
Posts: 13
#3: Dec 6 '06

re: Show the highest and lowest price item sold this month.(SQL)


thanx very much, i didnt think it was that simple.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,880
#4: Dec 6 '06

re: Show the highest and lowest price item sold this month.(SQL)


Quote:

Originally Posted by owz

thanx very much, i didnt think it was that simple.

No problem.

Mary
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#5: Dec 6 '06

re: Show the highest and lowest price item sold this month.(SQL)


Quote:

Originally Posted by owz

Expand|Select|Wrap|Line Numbers
  1.  SELECT  CarSales.Car_Reg,MAX (Purchased_Price) AS Highest_Sale
  2. FROM CarSales
  3. WHERE  Purchased_Price=(SELECT MIN(Purchased_Price)AS Smallest_Sale
  4.                                                                                         FROM CarSales)=
  5.  (((Month([Date_Of_Purchase]))=IIf(Month(Now())=1,12,Month(Now()))))
  6. GROUP BY [CarSales].[Car_Reg] ;

Did you mean to exclude January completely from your query?
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,880
#6: Dec 7 '06

re: Show the highest and lowest price item sold this month.(SQL)


Quote:

Originally Posted by NeoPa

Did you mean to exclude January completely from your query?

Ade right it should be:

Expand|Select|Wrap|Line Numbers
  1. WHERE (((Month([Date_Of_Purchase]))=IIf(Month(Now())=1,12,Month(Now())-1)))

Mary
Reply


Similar Microsoft Access / VBA bytes