2 Votes Vote

Calculate percentage of used fields(columns) in MySQL

Posted by topdog 516 days ago Questions| columns calculate fields columns All

Hi there,

I would like to know if there is any query to calculate the count of used fields(columns) in a table for every row(record).

I want to update my table new field called percentage usage by calculating

(total number of used columns) / (total number columns) * 100

for all records.

Any suggestion is appreciated. Thanks


For example:

I have a table named leads:

Name     Age      Designation    Address

Jack      25      programmer     chennai   
Ram       30      -----------    ----------                   
Rob       35      Analyst        ----------                     

I have added a new column called usagepercent and I want to update the new field as

Name     Age      Designation    Address     usagepercent

Jack      25      programmer     chennai      100
Ram       30      -----------    ----------    50
Rob       35      Analyst        ----------    75

------- indicates empty

Originally asked by: RSGanesh on Stack Overflow

Discuss Bury


Who Voted for this Question