Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Regarding about select statement

Author  Topic 

murgodrudra
Starting Member

1 Post

Posted - 2012-05-28 : 03:26:55
select sum(No_of_study)as Ct from financeOutsourcingDetails where mod_name ='ct' and hosp_name='Ramesh Hospital'

select hosp_name as hosp,sum(No_of_study)as Mri,sum(tot_amt) as total_amount from financeOutsourcingDetails where mod_name ='mri' group by Hosp_name

i want output like below

hosp_name , No_of_mri ,no_of_ct, Total_amt
Sugana
hospital 28 34 150000


Rudra

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-28 : 03:57:18
[code]
select hosp_name as hosp,
sum(No_of_study)as Mri,
(select sum(No_of_study)as Ct from financeOutsourcingDetails where mod_name ='ct' and hosp_name='Ramesh Hospital') as no_of_ct
sum(tot_amt) as total_amount
from financeOutsourcingDetails
where mod_name ='mri'
group by Hosp_name
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-28 : 13:23:15
this maybe?

select hosp_name as hosp,
sum(case when mod_name ='mri' then No_of_study end) as Mri,
sum(case when mod_name ='ct' then No_of_study end) as no_of_ct,
sum(tot_amt) as total_amount
from financeOutsourcingDetails
group by Hosp_name


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-05-30 : 03:28:59
quote:
Originally posted by visakh16

this maybe?

select hosp_name as hosp,
sum(case when mod_name ='mri' then No_of_study end) as Mri,
sum(case when mod_name ='ct' then No_of_study end) as no_of_ct,
sum(tot_amt) as total_amount
from financeOutsourcingDetails
group by Hosp_name


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




Yes. Also add where condition
hosp_name='Ramesh Hospital'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-30 : 15:37:35
shouldbe inside i guess

select hosp_name as hosp,
sum(case when mod_name ='mri' then No_of_study end) as Mri,
sum(case when mod_name ='ct' and hosp_name='Ramesh Hospital' then No_of_study end) as no_of_ct,
sum(tot_amt) as total_amount
from financeOutsourcingDetails
group by Hosp_name





------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -