Announcement

Collapse
No announcement yet.

Summe aus zwei Tabellen?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Summe aus zwei Tabellen?

    Hallo!

    Ich komme bei folgender Abfrage nicht weiter. Habe zwei Summen und möchte daraus ein ergebniss erzeugen. Also...
    Code:
     SELECT SUM( forum_topics ) AS topic_total, SUM( forum_posts ) AS post_total
    FROM phpbb_forums
    UNION
    SELECT SUM( forum_topics ) AS topic_total, SUM( forum_posts ) AS post_total
    FROM allover_forums
    da bekomme ich als Ergebniss:
    48 50
    2 8

    Ich hätte aber gern als Ergebniss:
    50 58

    Habe es so versucht, klappt aber nicht.
    Code:
    CREATE TEMPORARY TABLE tmp_forums
     SELECT SUM( forum_topics ) AS topic_total, SUM( forum_posts ) AS post_total
    FROM phpbb_forums
    INSERT INTO TABLE
    SELECT SUM( forum_topics ) AS topic_total, SUM( forum_posts ) AS post_total
    FROM allover_forums 
    SELECT SUM( topic_total ) AS topic_total, SUM( post_total ) AS post_total
    FROM tmp_forums
    Wie kann ich das Problem lösen?

  • #2
    Hallo,

    dieses Problem läßt sich z.B. mit einer Derived-Table lösen:
    [highlight=sql]
    select sum(all_forums.ftopics) topic_total, sum(all_forums.fposts) post_total
    from (
    SELECT forum_topics ftopics, forum_posts fposts
    FROM phpbb_forums
    UNION ALL
    SELECT forum_topics, forum_posts
    FROM allover_forums) all_forums
    [/highlight]

    Gruß Falk
    Wenn du denkst du hast alle Bugs gefunden, dann ist das ein Bug in deiner Denksoftware.

    Quellcode ohne ein Mindestmaß an Formatierung sehe ich mir nicht an! Ich leiste keinen Privatsupport per Mail oder PN!

    Comment

    Working...
    X