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
 

 

SQL Query to eliminate lowest value and get count

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Sudhir KL

New User


Joined: 15 Feb 2008
Posts: 17
Location: Safe Planet

PostPosted: Mon May 31, 2010 2:39 pm    Post subject: SQL Query to eliminate lowest value and get count
Reply with quote

How to exclude a minimum value while calculating sum in a SQL query. The values are grouped by an ID column. ( Decimal column)

EX. If there are 3 values 50,100,200
While calculating sum we should exclude the lowest one i.e 50 and result should be 300..
If there are duplicates,
50,50, 100,200 ...then the count should be 350( excluding the latest duplicate value)

How do u write sql query for it.
Back to top
View user's profile Send private message

Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 31, 2010 2:51 pm    Post subject:
Reply with quote

Code:

SELECT COL1,                                       
       (SUM(VAL_COL) - MIN(VAL_COL))   
FROM tabname
GROUP BY COL1;                                     
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Mon May 31, 2010 2:56 pm    Post subject:
Reply with quote

select sum(col1) - min(col1) from table1

(oops : too late)
Back to top
View user's profile Send private message
Sudhir KL

New User


Joined: 15 Feb 2008
Posts: 17
Location: Safe Planet

PostPosted: Mon May 31, 2010 3:05 pm    Post subject:
Reply with quote

thank you very much
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 31, 2010 3:12 pm    Post subject:
Reply with quote

Sudhir KL wrote:
thank you very much

Alrite but I still couldn't get matter of count in subject part... icon_confused.gif


SQL Query to eliminate lowest value and get count
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Mon May 31, 2010 5:39 pm    Post subject: Reply to: SQL Query to eliminate lowest value and get count
Reply with quote

count ... just the wrong word choice!
Back to top
View user's profile Send private message
Sudhir KL

New User


Joined: 15 Feb 2008
Posts: 17
Location: Safe Planet

PostPosted: Mon May 31, 2010 5:47 pm    Post subject: Reply to: SQL Query to eliminate lowest value and get count
Reply with quote

Quote:
SQL Query to eliminate lowest value and get count


Quote:
count ... just the wrong word choice!

It should have been something like below.

SQL Query to substract the lowest value in the column and get the SUM total
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 31, 2010 10:01 pm    Post subject: Re: Reply to: SQL Query to eliminate lowest value and get co
Reply with quote

Sudhir KL wrote:
Quote:
SQL Query to eliminate lowest value and get count


Quote:
count ... just the wrong word choice!

It should have been something like below.

SQL Query to substract the lowest value in the column and get the SUM total

Ohh.. ok... I thought you needed count of records for each group by records or something...
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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