Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

How yo make these two queires to one please

$
0
0

Hello There,

Could you please assist me to solve this, basically the below is 2 sql statements how can i convert these two queries to one, please

---Query 1
select  languagetype , Indication, COUNT(AcctID) as Clients, AVG(TaxRate1) as SavingRtAvg_RT, SUM(BeforeStats) as BeforeSecs, CASE WHEN Indication = 'Action' THEN COUNT(AcctID) END as CheckerPark, CASE WHEN Indication = 'NoAction' THEN COUNT(AcctID) END as NONCheckerPark
INTO #Temp
from Mars.Outfitter
where period = 'Q1-2013'
group by     languagetype , Indication
order by  LanguageType, Indication
-------------------------
---Query 2----
select  languagetype , a.Indication, a.Clients,  a.SavingRtAvg_RT, a.BeforeSecs, (CONVERT(Decimal(18,4),a.CheckerPark)/(a.CheckerPark+b.NONCheckerPark)) as Pct
from #temp a left outer join (select * from #temp where Indication = 'NoAction') b on a.languagetype = b.languagetype                  and a.Indication = 'Action'
DROP TABLE #Temp

Thank you in Advance

Milan




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>