View previous topic :: View next topic
|
Author |
Message |
Sudhir KL
New User
Joined: 15 Feb 2008 Posts: 17 Location: Safe Planet
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Code: |
SELECT COL1,
(SUM(VAL_COL) - MIN(VAL_COL))
FROM tabname
GROUP BY COL1;
|
|
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
select sum(col1) - min(col1) from table1
(oops : too late) |
|
Back to top |
|
|
Sudhir KL
New User
Joined: 15 Feb 2008 Posts: 17 Location: Safe Planet
|
|
|
|
thank you very much |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Sudhir KL wrote: |
thank you very much |
Alrite but I still couldn't get matter of count in subject part...
SQL Query to eliminate lowest value and get count |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
count ... just the wrong word choice! |
|
Back to top |
|
|
Sudhir KL
New User
Joined: 15 Feb 2008 Posts: 17 Location: Safe Planet
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
|