Abdu Abdul

Abdu Abdul

  • 1.8k
  • 349
  • 4.3k

Sum created columns at runtime mysql

Jan 15 2022 10:20 PM

i want to sum up values of a row in a single column using MySQL. I have tried all the below codes but nothing seems to work, i need help please

What I have tried:

 

SELECT employee.dept,employee.loc, employee.work, 
COUNT(IF(employee_info.emp_date = '2021-11-01', employee_info.emp_date, NULL)) AS a,
 COUNT(IF(employee_info.emp_date = '2021-11-02', employee_info.emp_date, NULL)) AS b,
  COUNT(IF(employee_info.emp_date = '2021-11-02', employee_info.emp_date, NULL)) AS c, SUM("a"+"b"+"c") AS total FROM employee_info INNER JOIN employee ON employee_info.employee_number = employee.employee_number GROUP BY employee.dept WITH ROLLUP

SELECT employee.dept,employee.loc, employee.work, 
COUNT(IF(employee_info.emp_date = '2021-11-01', employee_info.emp_date, NULL)) AS a,
 COUNT(IF(employee_info.emp_date = '2021-11-02', employee_info.emp_date, NULL)) AS b,
  COUNT(IF(employee_info.emp_date = '2021-11-02', employee_info.emp_date, NULL)) AS c, SUM('a'+'b'+'c') AS total FROM employee_info INNER JOIN employee ON employee_info.employee_number = employee.employee_number GROUP BY employee.dept WITH ROLLUP

SELECT employee.dept,employee.loc, employee.work, 
COUNT(IF(employee_info.emp_date = '2021-11-01', employee_info.emp_date, NULL)) AS a,
 COUNT(IF(employee_info.emp_date = '2021-11-02', employee_info.emp_date, NULL)) AS b,
  COUNT(IF(employee_info.emp_date = '2021-11-02', employee_info.emp_date, NULL)) AS c, 'a'+'b'+'c' AS total FROM employee_info INNER JOIN employee ON employee_info.employee_number = employee.employee_number GROUP BY employee.dept WITH ROLLUP

 


Answers (3)