473,480 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calculate percentage for each row

4 New Member
Hi,

Would like to get percentage for generated column. Any idea on how to do that??

Following SQL statement

Expand|Select|Wrap|Line Numbers
  1. SELECT s.Selection_Desc, count(u.user_id)
  2. from tbl_system_selection s, tbl_user u, tbl_user_company c
  3. where s.selection_type = 'INDUSTRY'
  4. and u.User_Company_ID = c.Company_ID 
  5. and c.Company_Industry_ID = s.Selection_ID 
  6. and u.user_activated = '1'
  7. group by s.selection_id

gives the result of

======================================
Expand|Select|Wrap|Line Numbers
  1. Selection_desc  count(u.user_id)
  2.  
  3. Marketing         44
  4. Sales               54
  5. Finance           100
=======================================

i would like to get percentage for each row

for example Finance shd give 50% (100/(45+55+100))*100)

======================================
Expand|Select|Wrap|Line Numbers
  1. Selection_desc  count(u.user_id)  perc
  2.  
  3. Marketing         45                       22.5
  4. Sales               55                       27.5
  5. Finance           100                      50
=====================================
Nov 9 '07 #1
3 8626
Atli
5,058 Recognized Expert Expert
Hi.

This is something I would do using a external API, like PHP. It would be much simpler than doing it via the MySQL query, if it is even possible.

If this has to be done via MySQL I would suggest using a stored procedure.
Nov 9 '07 #2
smileyangeluv
4 New Member
is there any way, for example, like nested query?
Nov 12 '07 #3
amitpatel66
2,367 Recognized Expert Top Contributor
is there any way, for example, like nested query?
Expand|Select|Wrap|Line Numbers
  1. select mgr, COUNT(mgr),((count(mgr)/(SELECT COUNT(*) from emp)) * 100) from emp where mgr IS NOT NULL group by mgr
  2.  
The above query gives me the % for the no of employees unser a particular manager. try applying this logic to your query for finding the %

I hope this helps!!
Nov 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
18519
by: Don Leverton | last post by:
Hi Folks, I *can* calculate the Gross Profit Percentage where both the Cost and SellPrice are known, using the formula: (SellPrice - Cost) / SellPrice = GPP eg ($24.92 - $14.95) / $24.92 =...
5
4353
by: James Conrad StJohn Foreman | last post by:
Have found http://www-128.ibm.com/developerworks/db2/library/techarticle/lyle/0110lyle.html which is quite helpful, but doesn't quite tell me what I want. I have a table, advertising_spend with...
1
5100
by: toluj | last post by:
Hi, pls could anyone help me with the script to calculate the percentage btwn two fields in a table.
7
43830
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics...
39
3282
by: Umesh | last post by:
Plese help. Is there any software by which we can do that?
3
9968
by: tulikapuri | last post by:
Dear Friends, I am using the method to cal. percentage in report but no sucess it gives #Num! instead of a number. I am following the steps as given in help to calculate percentage value on a...
7
5521
by: ngweixiong | last post by:
Hi, I have a Ms Access query which i used to calculate how many times the leadtime is a) less than 7 days b) 7-14 days c) more than 14 days With the query results, i will like to convert...
4
5957
ollyb303
by: ollyb303 | last post by:
Hello, Trying to help a friend/colleague out with a database and we've both drawn a blank. Not even sure if this is possible. The database has a table (Table1) with a several columns: ID,...
17
2182
by: MNNovice | last post by:
Calculate net amount based on conditions ________________________________________ I need to calculate a net amount that is based on FedRatio. Normally the FedRatio is set to be 80% but there are a...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.