473,327 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

mysql - get the percentage of a row count of all counts

29
Hi All , I would like to in one query from the same table of say first names count all the occurrences of the various first names in a column called thecount and create another column called percentage that give the percentage of the count of an individual of the sum of all the counts of first names so all fname sara is 10%
say select count(*) as thecount , fname, count(*)/sum(count(*)) as percentage and you get
thecount fname percentage
4 sara 10
19 mike
7 lou
10 sam
Jun 16 '10 #1
2 21914
JKing
1,206 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. SELECT fname, count(fname) as nameCount, count(fname) / (SELECT count(fname) FROM names)*100 as percent FROM names
  2. GROUP BY fname
  3.  
This SQL should do the trick.
Jun 21 '10 #2
Hegli
1 Bit
Hi

How do you then get it to write the percentage?

Sorry - found the solution :)
Aug 26 '23 #3

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

Similar topics

6
by: Floris van den Berg | last post by:
Is something like the following possible? SELECT products.id, count(*) as counter FROM products, keywords WHERE keywords.keyword in ("bla","hi","hello") AND counter > 2; Can't get it to work...
1
by: Nikola Skoric | last post by:
Hi there... Yes, I know there exists a suport forum for discussion about problems with phpBB, but noone there seems to know the solution to my problem... so I ask here. I've been messing...
1
by: Eddie | last post by:
I am having a strange issue with MySQL. I just installed it on my Zaurus and loaded a few of my databases in it. All very small. When I do a count withoout a where, it hangs. It does this on all...
1
by: t123 | last post by:
I have a select count() that seams be ignoring one clause. Data: Table: ID CA-Char CB-Int 1 dsfsd 6 2 dsfsd 0 3 dsfsd 1 4 sdrtt 1 SQL is:
7
by: Paul Serby | last post by:
Why does '*select count(id) from "tblContacts"'* do a sequential scan when the field '*id*' is indexed using a btree? MySql simply looks at the index which is keeping a handy record of the...
7
by: Matteo Rattotti | last post by:
Hi all, i've noticed a strange beaviour of string.count: in my mind this code must work in this way: str = "a_a_a_a_" howmuch = str.count("_a_") print howmuch -> 3
3
by: inamul | last post by:
I want to see how many people have registered from Countries and also want to Sum the total Table fields 1. Name, 2. Email 3 Country I use this query to get number of people registered...
4
by: ahmurad | last post by:
Dear Xperts, In my database table some fault code type records are inserted and the values are like bellows: Error:2/FC:10; 00:15:13 16/03/2009; Error:2/FC:20; 00:15:15 16/03/2009; ...
1
by: claudfs | last post by:
Hey Guys, Ok here is my problem: There is around 350 rows in the db. All the variables $actor_id, $comment_id and $likes_id are all uid's for facebook users Now i want to group and sum...
8
by: munkee | last post by:
Hi people, Im struggling with this quite hard to explain database query. How would I count only once the (many) occurance of a record within a one to many relationship. I have the following...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.