Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Doubt in BETWEEN ... AND clause

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Doubt in BETWEEN ... AND clause
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    Post subject:
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    Post subject:
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    Post subject: Re: Doubt in BETWEEN ... AND clause
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Doubt in MFS abdulrafi IMS DB/DC 2 Fri Oct 21, 2016 3:09 pm
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts [SQL0029] INTO clause missing from em... HABBIE DB2 2 Fri Sep 04, 2015 3:54 pm
No new posts Doubt on GETMAIN, FREEMAIN behaviour Arunkumar Chandrasekaran CICS 3 Sun Aug 30, 2015 9:22 pm
No new posts 3-D Table with nested DEPENDING ON Cl... VivekKhanna COBOL Programming 5 Sat Aug 08, 2015 11:18 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us