Warning: file_put_contents(/home/httpd/vhosts/phprog.ch/httpdocs/wp-content/advanced-cache.php): Failed to open stream: Permission denied in /home/httpd/vhosts/phprog.ch/httpdocs/wp-content/plugins/comet-cache/src/includes/traits/Plugin/InstallUtils.php on line 349 SUM() - My-Web-Professionals-Blog

SUM()

Anzahl bestellte Artikel ausgeben.

      SELECT SUM(Quantity) AS „Total Anzahl bestellte Artikel“ FROM OrderDetails

Sum

Anzahl Bestellmenge (Quatities) pro Land.

      SELECT c.country, count(o.orderid) AS Anzahl , sum(od.quantity)

      AS Anzahl_Quantities

                  FROM customers AS c

                  LEFT JOIN orders AS o ON o.customerid = c.customerid

                  LEFT JOIN orderdetails AS od ON od.orderid = o.orderid

                  GROUP BY c.country

                  ORDER BY Anzahl

Sum_Bsp2

 

Einnahmen pro Land.

      SELECT c.country, COUNT(o.orderid) AS Anzahl , ROUND(SUM(od.quantity*p.price),2)
      AS Einnahmen

                  FROM customers AS c

                  LEFT JOIN orders AS o ON o.customerid = c.customerid

                  LEFT JOIN orderdetails AS od ON od.orderid = o.orderid

                  LEFT JOIN products AS p ON p.productid = od.productid

                  GROUP BY c.country

                  ORDER BY Einnahmen DESC

Sum_Bsp3

SUM()
Markiert in:     

Schreibe einen Kommentar