Captai-N Captai-N - 13 days ago 6
MySQL Question

Count a special column in MySQL

How can i count the data from a column if sort them first

SELECT * FROM erfasst
WHERE jahr >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND jahr < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY


enter image description here

I need the output from gesamt (4589) as result. If there are many results, mysql should count the gesamt column together.

Answer

You want to sum all values of gesamt:

SELECT SUM(gesamt) AS gesamt 
FROM erfasst
WHERE jahr >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
    AND jahr < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY