Skip to content
Fix Code Error

How to calculate percentage with a SQL statement

March 13, 2021 by Code Error
Posted By: Anonymous

I have a SQL Server table that contains users & their grades. For simplicity’s sake, lets just say there are 2 columns – name & grade. So a typical row would be Name: “John Doe”, Grade:”A”.

I’m looking for one SQL statement that will find the percentages of all possible answers. (A, B, C, etc…) Also, is there a way to do this without defining all possible answers (open text field – users could enter ‘pass/fail’, ‘none’, etc…)

The final output I’m looking for is A: 5%, B: 15%, C: 40%, etc…

Solution

I have tested the following and this does work. The answer by gordyii was close but had the multiplication of 100 in the wrong place and had some missing parenthesis.

Select Grade, (Count(Grade)* 100 / (Select Count(*) From MyTable)) as Score
From MyTable
Group By Grade
Answered By: Anonymous

Related Articles

  • Remove the newline character in a list read from a file
  • SQLException: No suitable Driver Found for…
  • Vue.js: Calculate average and update field
  • How can i display data from xml api in flutter?
  • Fastest way to iterate over all the chars in a String
  • How do I check to see if a user Input matches an…
  • Problems Installing CRA & NextJS from NPM…
  • Using if(isset($_POST['submit'])) to not display…
  • Finding the average of an array using JS
  • how to determine which bar was clicked on a chart js
  • What are the new features in C++17?
  • Display Object list from server in a Select option in Vue
  • Python How to print list to list
  • How can I print the report without the first in the list
  • Polymer 1.0 'array-style' path accessors,…
  • I want to create a SQLite database like in the…
  • easiest way to extract Oracle form xml format data
  • Issue with iron-ajax request
  • How to change the color of vaadin-select-text-field…
  • Flip first name and last name to last name first name
  • How can I append a query parameter to an existing URL?
  • Fix top buttons on scroll of list below
  • Using enums in a spring entity
  • Making a grading calculator using javascript
  • data.table vs dplyr: can one do something well the…
  • Sort table rows In Bootstrap
  • SQL query return data from multiple tables
  • SQL find sum of entries by date including previous date
  • pyspark window function from current row to a row…
  • Format Column Data before passing to Vue Good-Table
  • Combining items using XSLT Transform
  • flutter - add network images in a pdf while creating…
  • Active tab issue on page load HTML
  • How do you easily create empty matrices javascript?
  • "Large data" workflows using pandas
  • How to set border's thickness in percentages?
  • How do I limit the number of digits from 6 to 4 in…
  • Vue.js counting json value
  • How to edit `cell[i]` in data grid view C# win form…
  • Align input points with multiple variable lengths
  • Change private static final field using Java reflection
  • Is it possible to apply CSS to half of a character?
  • How to handle numerical variables in categorical…
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • NextJS: How to navigate from url to a custom path?
  • How to filter a RecyclerView with a SearchView
  • Pandas pivot_table: filter on aggregate function
  • How to use html template with vue.js
  • MySQL GROUP BY two columns
  • Linq order by, group by and order by each group?
  • Inner join with 3 tables in mysql
  • insert tables in dataframe with years from 2000 to…
  • meta_query search names when they have middle…
  • Using Auto Layout in UITableView for dynamic cell…
  • Sorting A Table With Tabs & Javascript
  • Auto-fit TextView for Android
  • Error creating bean with name 'entityManagerFactory'…
  • Cant figure out what Im doing wrong. Unhandled…
  • After a little scroll, the sticky navbar just is not…
  • jquery to loop through table rows and cells, where…
  • Changing Icon Color behind ListTile in an…
  • Power Query: Calculate date/time instances within…
  • Django - update inline formset not updating
  • How to find Control in TemplateField of GridView?
  • HTML table with 100% width, with vertical scroll…
  • How to separate parts of the string with a specific…
  • How do i arrange images inside a div?
  • The definitive guide to form-based website authentication
  • How to import XML file into MySQL database table…
  • React - componentWillReceiveProps alternative
  • Chrome / Safari not filling 100% height of flex parent
  • Why is this ember test failing - Ember JS, Controllers
  • Difference between Svelte REPL and local output
  • R doesn't display percentages when trying to build a…
  • How do I use 3DES encryption/decryption in Java?
  • Bootstrap 3 - 100% height of custom div inside column
  • Cannot update nested dictionary properly
  • Programmatically Lighten or Darken a hex color (or…
  • Vue + VUEX + Typescript + Vue Router. component not…
  • How do I count unique visitors to my site?
  • Ukkonen's suffix tree algorithm in plain English
  • boostrap modal not updating with vue js v2 two way binding
  • Split cell value that based on a delimiter and…
  • How to fix overlapping issue in the Qweb reports?
  • Instance member can't be accessed using static access
  • Firestore, Security Rules, how to limit a size of…
  • Rails wrong number of arguments error when…
  • Octave using 'for' statement to show two animations…
  • R: Calculate and display percentages using dplyr and…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Calculate sum for group of dynamic table rows in jquery
  • vaadin combobox load wrong custom style
  • Create a DataFrame from a XML File
  • Cypress finding DOM element using multiple contains
  • TSQL PIVOT MULTIPLE COLUMNS
  • POI Word Unable to merge newly created cell vertically
  • Multiple elements per v-for loop
  • Start redis-server with config file
  • GIT commit as different user without email / or only email
  • Binning column with python pandas

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Python Pandas: Get index of rows which column matches certain value

Next Post:

SQL Server – SELECT FROM stored procedure

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error