Kunden im Februar
mysql> SELECT R_Kunde, COUNT(*) AS "Aufträge" FROM rechnungen WHERE R_Datum BETWEEN "2013-02-01" AND "2013-02-28" GROUP BY R_Kunde;
+---------+-----------+
| R_Kunde | Aufträge |
+---------+-----------+
| 1 | 3 |
| 2 | 1 |
+---------+-----------+
Alle Rechnungen mit Gesamtsumme von Kunde 1
mysql> SELECT R.R_Nr, (RP.Stck*RP.Einzelpreis) AS Summe FROM rechnung_pos AS RP, rechnungen AS R WHERE RP.R_Nr = R.R_Nr AND R.R_Kunde = 1 AND R.R_Datum BETWEEN "2013-02-01" AND "2013-02-28";
+------+-------+
| R_Nr | Summe |
+------+-------+
| 2 | 280 |
| 3 | 100 |
| 4 | 200 |
+------+-------+
Gesamtgewinn durch Kunde 1
mysql> SELECT SUM(RP.Stck*RP.Einzelpreis) AS Summe FROM rechnung_pos AS RP, rechnungen AS R WHERE RP.R_Nr = R.R_Nr AND R.R_Kunde = 1 AND R.R_Datum BETWEEN "2013-02-01" AND "2013-02-28";
+-------+
| Summe |
+-------+
| 580 |
+-------+
Meist genutzte Geräte
mysql> SELECT RP.G_Nr, G.G_Bezeichnung, COUNT(*) AS "Ausgeliehen" FROM rechnung_pos AS RP, geraete as G WHERE RP.G_Nr = G.G_Nr GROUP BY RP.G_Nr ORDER BY 3 DESC;
+------+----------------+-------------+
| G_Nr | G_Bezeichnung | Ausgeliehen |
+------+----------------+-------------+
| 5 | Thinkpad T430s | 4 |
| 1 | Thinkpad X61 | 1 |
| 3 | Thinkpad T61p | 1 |
+------+----------------+-------------+