SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Regarding about select statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

murgodrudra
Starting Member

India
1 Posts

Posted - 05/28/2012 :  03:26:55  Show Profile  Reply with Quote
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)

Singapore
16745 Posts

Posted - 05/28/2012 :  03:57:18  Show Profile  Reply with Quote

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



KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 05/28/2012 :  13:23:15  Show Profile  Reply with Quote
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

India
22460 Posts

Posted - 05/30/2012 :  03:28:59  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
47023 Posts

Posted - 05/30/2012 :  15:37:35  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000