Solved

Get the total of the count

Posted on 2014-12-30
3
87 Views
Last Modified: 2014-12-30
Hi,

I have this query

select count(*) as Total, ST.ApplicationType,
cast(((count(*) * 100.0) / 741) as DECIMAL(10,2)) as Percentage from AppRepository AP
left join SourceType ST on AP.applicationType = ST.SourceID
where AP.Retired = 0
group by AP.ApplicationType, ST.ApplicationType

Open in new window


that generate this output

Total    ApplicationType                                        Percentage 
5	Access	                                                      0.67
21	Client	                                                      2.83
1	Crystal Reports	                                     0.13
303	Distributed	                                    40.89
25	Distributed/Mainframe	                   3.37
1	Function	                                                      0.13
242	Mainframe	                                     32.66
1	Other	                                                      0.13
24	Web - External/Distributed	                   3.24
76	Web - Internal/Distributed	                  10.26
41	Web - Internal/External -  Distributed	 5.53
1	Web - Internal/Mainframe	                   0.13

Open in new window



the problem that I am having is the percentage in my query I hard coded "741"
that supose to be the total of my cound and I don't know how to get it.

In my query I have the percentage:

cast(((count(*) * 100.0) / 741) as DECIMAL(10,2)) as Percentage

cast(((count(*) * 100.0) / ?????????) as DECIMAL(10,2)) as Percentage


741 is the sum of my count how can I do this

sum(count(*)) ?????

not sure please help
0
Comment
Question by:lulu50
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
Ray earned 500 total points
ID: 40524122
See edited code ... Note the only change if the query that replaces your hard coded number
select count(*) as Total, ST.ApplicationType,
cast(((count(*) * 100.0) / (select count(*) from AppRepository where AP.Retired = 0 ) as DECIMAL(10,2)) as Percentage 
from AppRepository AP
left join SourceType ST on AP.applicationType = ST.SourceID
where AP.Retired = 0
group by AP.ApplicationType, ST.ApplicationType

Open in new window

0
 

Author Comment

by:lulu50
ID: 40524151
Ray!!!!

Thank you for your help

it works!!!!!!!!!!!!!!!!!!!!!!!!!!
0
 

Author Closing Comment

by:lulu50
ID: 40524152
Thank you
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now