user2669261
user2669261

Reputation: 416

Mysql: Sum calculated columns

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

Upvotes: 0

Views: 635

Answers (2)

Fuzzy
Fuzzy

Reputation: 3810

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;

Upvotes: 1

Tudor Constantin
Tudor Constantin

Reputation: 26861

Sure it's possible:

select t.TEILEID, SUM(t.BESTAND - t.RESERVIERT) from ...
GROUP BY t.TEILEID

Upvotes: 0

Related Questions