Announcement

Collapse
No announcement yet.

Mehrere Counts mit Where in Select

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

  • Mehrere Counts mit Where in Select

    Hallo,
    ich bin relativ neu in der Materie und brauche Hilfe.

    Mein Problem,
    ich habe mehrere Tabellen von denen ich die Zeilenanzahl mit COUNT(*) abrufe, jedoch mit where Klausel. es handelt sich um 8 abfragen die ich ohne probleme einzeln formulieren konnte.
    SELECT count(*)AS "Zahl1" FROM tabelle1 where wert1 >= 1222935000 and wert1 < 1222938600;
    --> alles dasselbe schema


    jetzt würde ich das ganze gerne in eine Ergebnistabelle, d.h. eine CREATE TABLE, oder INSERT INTO anweisung mit select anweisung und 8 count(*), die nicht mit UNION alle Werte in einer Spalte speichert...

    Ergebnisttabelle:
    wert1|wert2|wert3|...
    -----------------------------
    8 | 3| 5 |.....

    Meine Frage:
    Da ich keine Vorstellung habe wie ich die ganzen selects bündeln kann soll oder verbinden kann hatte ich gehofft hier einen tipp zu bekommen ob eine Realisierung möglich ist und wenn ja wie?

    lG DW

  • #2
    Hallo,

    sollte eigentlich einfach so gehen:
    [highlight=sql]
    create table count_tab as (
    select
    (SELECT count(*) FROM tabelle1 where wert1 >= 1222935000 and wert1 < 1222938600) Zahl1,
    (SELECT count(*) FROM tabelle2 where wert2 >= 1222935000 and wert1 < 1222938600) Zahl2,
    ...
    )
    [/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


    • #3
      Originally posted by Falk Prüfer View Post
      Hallo,

      sollte eigentlich einfach so gehen:
      [highlight=sql]
      create table count_tab as (
      select
      (SELECT count(*) FROM tabelle1 where wert1 >= 1222935000 and wert1 < 1222938600) Zahl1,
      (SELECT count(*) FROM tabelle2 where wert2 >= 1222935000 and wert1 < 1222938600) Zahl2,
      ...
      )
      [/highlight]

      Gruß Falk

      Danke für die schnelle Antwort hat bestens geklappt

      lG
      DW

      Comment

      Working...
      X