Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get the total of the count

Posted on 2014-12-30
3
Medium Priority
?
97 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Ray earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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