View previous topic :: View next topic
|
Author |
Message |
logaas
New User
Joined: 19 Feb 2005 Posts: 25 Location: chennai
|
|
|
|
Hi all,
Can we use subquery & BETWEEN....AND clause in DB2.
I am getting an error if I execute the following query:
SELECT SUM(DISTINCT price)
FROM products
WHERE price
BETWEEN
(SELECT MIN(price) FROM products)
AND
(SELECT MAX(price) FROM products);
I am getting -104 if I execute the above query.
Please help me out.
Bye
logaas. |
|
Back to top |
|
|
steve
New User
Joined: 24 Mar 2005 Posts: 16 Location: Long Island
|
|
|
|
You can use sub queries for BETWEEN.. AND. U must use literals |
|
Back to top |
|
|
steve
New User
Joined: 24 Mar 2005 Posts: 16 Location: Long Island
|
|
|
|
Im sorry... You cant use.. sub queries for BETWEEN.. AND |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Try this code
Code: |
SELECT SUM(DISTINCT price)
FROM products,
(select MIN(price) as MIN_PRICE,
MAX(price) as MAX_PRICE
FROM products
) MM
WHERE price between MM.MIN_PRICE and MM.MAX_PRICE
;
|
Dave |
|
Back to top |
|
|
|