Announcement

Collapse
No announcement yet.

SQL Syntax

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

  • SQL Syntax

    Hi

    Ich hoffe jemand kann mir weiterhelfen.

    Ich möchte aus einer Oracle Datenbank folgendes auslesen:

    Welcher Kunde im Jahr 1990, im jeweiligen Quartal, welchen Umsatz gemacht hat.

    NAME 1st Q 2nd Q 3rd Q 4th Q
    --------- ------------- --------------- ------------- ----------------------
    MAIER 347.90 5483.88 4473.99 6633.88
    KUNZE 77.99 66.88 333.88

    Danke für Eure Tipps!

    Gruß

  • #2
    Code:
    SELECT name, sum(q1) Q1, sum(q2) Q2, sum(q3) Q3, sum(q4) Q4
    FROM tablename
    WHERE jahr = 1990
    GROUP BY name

    Comment


    • #3
      ok, es gibt aber keine tabelle namens q1, q2 etc....

      Comment


      • #4
        entschuldige. ich hab deine frage wie es aussieht nicht richtig verstanden. das was du da tabellenähnlich aufgegliedert hast soll die ergebnismenge sein?

        dann musst du schon etwas mehr zur ausgangsposition sagen. man kann die ja schlecht ne query "vorsagen" ohne überhaupt die tabellen zu kennen, die du für deine abfrage verwenden willst.
        Zuletzt editiert von JenneB; 21.01.2008, 20:48. Reason: frage nicht richtig gelsen und somit ne unpassende antwort gegeben.

        Comment


        • #5
          ups, habe ich verwechselt.

          muss die spalte (sum(1st Q), sum(2nd Q), ...) nicht existieren?

          original fragestellung:

          Write a spooled report on the average order placed by each customer during the 4 quarters of the year 1990, detailing the average per customer, per quarter, ensuring that the SQL to be executed is not spooled to the output.

          hier ist das schema

          Zuletzt editiert von timtaylor; 21.01.2008, 20:52.

          Comment


          • #6
            bin nun soweit

            Code:
            select c.name,
            avg(case when to_char(order_date, 'Q') = '1' then s.total else null end) as "1st q",
            avg(case when to_char(order_date, 'Q') = '2' then s.total else null end) as "2nd q",
            avg(case when to_char(order_date, 'Q') = '3' then s.total else null end) as "3rd q",
            avg(case when to_char(order_date, 'Q') = '4' then s.total else null end) as "4th q"
            from sales_order s, customer c
            where to_char(order_date, 'yy') = 90 and
            s.customer_id = c.customer_id
            group by c.name
            jetzt muss ich nur noch die währung einfügen. hat jemand einen tipp für mich?

            danke!

            Comment

            Working...
            X