Home > Database > Mysql Tutorial > Here are some question-based titles that fit your provided content: * **How to Calculate Employee Survey Participation Percentage in MySQL?** * **What\'s the Correct Query to Determine Employee Surv

Here are some question-based titles that fit your provided content: * **How to Calculate Employee Survey Participation Percentage in MySQL?** * **What\'s the Correct Query to Determine Employee Surv

Susan Sarandon
Release: 2024-10-25 12:13:03
Original
596 people have browsed it

Here are some question-based titles that fit your provided content: 

* **How to Calculate Employee Survey Participation Percentage in MySQL?**
* **What's the Correct Query to Determine Employee Survey Participation Percentage in MySQL?**
* **Calculating

Calculating Percentage of Employee Survey Participation in MySQL

Your goal is to determine the percentage of employees in different groups who have taken a survey based on the "employees" and "surveys" columns in your MySQL table. You have provided a query that attempts to calculate the percentage, but it seems to be incorrect. Below is a revised query that should provide the desired results:

<code class="sql">SELECT group_name, employees, surveys, COUNT( surveys ) AS test1, 
concat(round(( surveys/employees * 100 ),2),'%') AS percentage
FROM a_test
GROUP BY employees</code>
Copy after login

Explanation:

  • The concat() function is used to create a string representation of the percentage value with two decimal places.
  • The calculation of the percentage is as follows: (surveys / employees * 100).
  • The round() function is used to round the result to two decimal places.

Here is the result of executing the revised query on the provided data:

group_name employees surveys test1 percentage
Awesome Group A 100 0 0 0.00%
Awesome Group B 200 190 190 95.00%
Awesome Group C 300 290 290 96.67%

This result shows the percentage of employees in each group who have taken the survey.

The above is the detailed content of Here are some question-based titles that fit your provided content: * **How to Calculate Employee Survey Participation Percentage in MySQL?** * **What\'s the Correct Query to Determine Employee Surv. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template