IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Doubt in BETWEEN ... AND clause


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
logaas

New User


Joined: 19 Feb 2005
Posts: 25
Location: chennai

PostPosted: Thu Apr 13, 2006 2:11 pm
Reply with quote

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
View user's profile Send private message
steve

New User


Joined: 24 Mar 2005
Posts: 16
Location: Long Island

PostPosted: Thu Apr 13, 2006 2:35 pm
Reply with quote

You can use sub queries for BETWEEN.. AND. U must use literals
Back to top
View user's profile Send private message
steve

New User


Joined: 24 Mar 2005
Posts: 16
Location: Long Island

PostPosted: Thu Apr 13, 2006 2:36 pm
Reply with quote

Im sorry... You cant use.. sub queries for BETWEEN.. AND
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Thu Apr 13, 2006 8:15 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Doubt about pl/1 (job offer) General Talk & Fun Stuff 5
No new posts NOT IN clause in COBOL pgm COBOL Programming 8
No new posts SUSBSCRIPT WITH SIGN IN PIC CLAUSE COBOL Programming 3
No new posts usage of CASE in WHERE clause DB2 10
Search our Forums:

Back to Top