Showing posts with label sum. Show all posts
Showing posts with label sum. Show all posts

Friday, March 9, 2012

Need a suggestion on how to revise this query

SELECT WBS2, (SUM(CASE WHEN wbs2 = '9001' THEN amount * - 1 END)) AS reimb
FROM LedgerAR
WHERE (WBS1 = '001-298') AND (WBS2 <> 'zzz') AND (WBS3 <> 'zzz') AND transtype = 'in'
GROUP BY wbs2

this is what the output looks like:

wbs2 amount
0141 0
1217 0
1218 0
1219 0
1222 0
1223 0
9001 3271.02

Id there a way to specify where I want this exact amount to display without having to a subquery. I would ideally like to take the 3271.02 and put it where wbs2 = '1217'

Any suggestions?

Thank You.You mean you want to reorder the results to that

9001, 3271.02

is in the second row?

Saturday, February 25, 2012

need -> max(sum(salary)) query

hi

i have a table employee:

dept ename salary
-- --- ---
10 A 2500
20 B 3500
30 C 4000
20 D 5500
10 E 4500
30 F 5200

FIRST QUERY:
select dept,sum(salary) from employee group by dept

the above one is working fine..

after working the first query output,
i want to select the dept,max(sum(salary)) from the table...

how?? could any one send me immediately...

thanks in advancethe below one query will give only the max(sum(salay))

-----
select max(sal) from (select sum(salary) as sal from employee
group by dept) as a
-------

but i need - Which DEPT has the max(sum(salary)) ??

need these two values:

dept, max(sum(salary))

thanks|||select top 1
dept
, sum(salary)
from employee
group
by dept
order
by sum(salary) desc|||hi
it works .

thanks rudy....