Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (Deutsch) » SQL Anywhere Server - SQL-Benutzerhandbuch » Daten abfragen und ändern » Allgemeine Tabellenausdrücke

 

Mehrere Tabellenausdrücke verwenden

Eine einzelne WITH-Klausel kann mehr als einen allgemeinen Tabellenausdruck definieren. Diese Definitionen müssen durch Kommas getrennt sein. Das folgende Beispiel listet die Abteilung auf, die die kleinste Lohnsumme sowie die Abteilung, die die größte Anzahl von Mitarbeitern hat.

WITH
  CountEmployees( DepartmentID, n ) AS
    ( SELECT DepartmentID, COUNT( * ) AS n
      FROM Employees GROUP BY DepartmentID ),
  DeptPayroll( DepartmentID, amt ) AS
     ( SELECT DepartmentID, SUM( Salary ) AS amt
       FROM Employees GROUP BY DepartmentID )
SELECT count.DepartmentID, count.n, pay.amt
FROM CountEmployees AS count JOIN DeptPayroll AS pay
ON count.DepartmentID = pay.DepartmentID
WHERE count.n = ( SELECT MAX( n ) FROM CountEmployees )
   OR pay.amt = ( SELECT MIN( amt ) FROM DeptPayroll );
Siehe auch