select - Percentages in MySQL - Between two columns in the same table -


i have mysql table looks this:

name    | pass |  fail | pass percent | fail percent  abdy    | 20   |  5    |              | bob     | 10   |  5    |              | cantona | 40   |  10   |              | dave    | 30   |  20   |              | 

i trying percentages:

like : passpercent = (pass/pass+fail)*100

can fill table single mysql code both columns??

the table hopefully:

name    | pass |  fail | pass percent | fail percent  abdy    | 20   |  5    |   80         |  20 bob     | 10   |  5    |   66         |  33 cantona | 40   |  10   |   80         |  20 dave    | 30   |  20   |   60         |  40 

that's absolutely possible.

to fill second table:

update mytable set pass_pct=(pass/pass+fail)*100,fail_pct=(fail/pass+fail)*100 

granted, generate during selection of first table (if don't want store results), like:

select name,pass,fail,(pass/pass+fail)*100 pass_pct,(fail/pass+fail)*100 fail_pct mytable 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -