Click here to Skip to main content
15,902,938 members
Home / Discussions / Database
   

Database

 
GeneralRe: SQL Query Problem Pin
dan!sh 7-Oct-09 5:55
professional dan!sh 7-Oct-09 5:55 
GeneralRe: SQL Query Problem Pin
Syed Shahid Hussain7-Oct-09 6:04
Syed Shahid Hussain7-Oct-09 6:04 
GeneralRe: SQL Query Problem Pin
Luc Pattyn7-Oct-09 8:45
sitebuilderLuc Pattyn7-Oct-09 8:45 
GeneralRe: SQL Query Problem Pin
Syed Shahid Hussain7-Oct-09 10:43
Syed Shahid Hussain7-Oct-09 10:43 
AnswerRe: SQL Query Problem Pin
J4amieC7-Oct-09 6:44
J4amieC7-Oct-09 6:44 
GeneralRe: SQL Query Problem Pin
mnatarajakumaran7-Oct-09 18:23
mnatarajakumaran7-Oct-09 18:23 
GeneralRe: SQL Query Problem Pin
J4amieC7-Oct-09 23:03
J4amieC7-Oct-09 23:03 
AnswerRe: SQL Query Problem Pin
Niladri_Biswas27-Oct-09 18:24
Niladri_Biswas27-Oct-09 18:24 
Try this

declare @tbl table(person varchar(50),name varchar(50),value int)
insert into @tbl
select 'xyz','a',10 union all select 'xyz','b',5 union all
select 'xyz','a',15 union all select 'xyz','b',4 union all
select 'xyz','c',1 union all select 'xyz','a',5 union all
select 'xyz','d',10 union all select 'xyz','a',10 union all
select 'abc','a',0 union all select 'abc','b',0 union all
select 'abc','c',0 union all select 'abc','d',0


;with cte as
(
select person,name,sum(value) as total from @tbl group by person,name
)

select person,'others' as name , SUM(total) as total from cte where name not in('a') 
group by person
union all
select person,'a' as name , SUM(total) as total from cte where name in('a') 
group by person
 order by person desc

Smile | :)

Niladri Biswas

QuestionBulk Import Error Pin
Vimalsoft(Pty) Ltd6-Oct-09 23:35
professionalVimalsoft(Pty) Ltd6-Oct-09 23:35 
AnswerRe: Bulk Import Error Pin
Eddy Vluggen6-Oct-09 23:49
professionalEddy Vluggen6-Oct-09 23:49 
GeneralRe: Bulk Import Error Pin
Vimalsoft(Pty) Ltd7-Oct-09 0:04
professionalVimalsoft(Pty) Ltd7-Oct-09 0:04 
AnswerRe: Bulk Import Error Pin
J4amieC6-Oct-09 23:54
J4amieC6-Oct-09 23:54 
GeneralRe: Bulk Import Error Pin
Vimalsoft(Pty) Ltd7-Oct-09 0:09
professionalVimalsoft(Pty) Ltd7-Oct-09 0:09 
GeneralRe: Bulk Import Error Pin
Vimalsoft(Pty) Ltd7-Oct-09 0:48
professionalVimalsoft(Pty) Ltd7-Oct-09 0:48 
GeneralRe: Bulk Import Error Pin
J4amieC7-Oct-09 0:58
J4amieC7-Oct-09 0:58 
Questiondelete stament Pin
mjawadkhatri6-Oct-09 19:04
mjawadkhatri6-Oct-09 19:04 
AnswerRe: delete stament Pin
Andy_L_J6-Oct-09 19:18
Andy_L_J6-Oct-09 19:18 
GeneralRe: delete stament Pin
mjawadkhatri6-Oct-09 19:19
mjawadkhatri6-Oct-09 19:19 
Questionhow i can backup my entire database using pl/sql developer Tool ver 7.1 ? Pin
E_Gold6-Oct-09 10:12
E_Gold6-Oct-09 10:12 
Questioninstall sql express 2005 question Pin
Jassim Rahma5-Oct-09 23:13
Jassim Rahma5-Oct-09 23:13 
AnswerRe: install sql express 2005 question Pin
Hristo-Bojilov5-Oct-09 23:43
Hristo-Bojilov5-Oct-09 23:43 
QuestionAdd a report to a Visual Studio Project Pin
Hardus Lombaard5-Oct-09 20:48
Hardus Lombaard5-Oct-09 20:48 
QuestionOracle query Pin
sandhya145-Oct-09 19:58
sandhya145-Oct-09 19:58 
AnswerRe: Oracle query Pin
Mycroft Holmes5-Oct-09 21:59
professionalMycroft Holmes5-Oct-09 21:59 
GeneralRe: Oracle query Pin
sandhya145-Oct-09 22:27
sandhya145-Oct-09 22:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.