Mysql: Sum calculated columns Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Mysql: Sum calculated columns without wasting too much if your time.

The question is published on by Tutorial Guruji team.

enter image description here

Hey there! I do have a question regarding SQL. Is there a way to sum the red marked values? So e.g. AAG will not be seperated into 2 columns but aggregated into one. So AAG 2 and AAG 4 become one single row with AAG 6

Help is appreciated 🙂 Have a nice day

Answer

this would do it:

You need to use SUM()

SELECT t.TEILEID
    , SUM(t.BESTAND - t.RESERVIERT)
FROM   TEILE t
      INNER JOIN AUFTRAGSPOSDS a ON a.TEILEID = t.TEILEID
WHERE  a.AUFTRNR = 15
GROUP BY t.TEILEID;

After reading your comment I think you need this:

SELECT t.TEILEID
    , SUM(t.BESTAND - t.RESERVIERT)
FROM   TEILE t
WHERE  t.TEILEID IN
                (SELECT a.TEILEID
                FROM   AUFTRAGSPOSDS a
                WHERE  a.AUFTRNR = 15)
GROUP BY t.TEILEID;
We are here to answer your question about Mysql: Sum calculated columns - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji