mysql Group by今天

时间:2018-12-10 18:37:08

标签: mysql

您好,我想只用mysql花费今天的所有数据。不幸的是,只有GROUP BY YEAR和MONTH

SELECT rechnung.*, re_kunden.*,  SUM(re_kunden.gpreis) as preise 
FROM rechnung
    LEFT JOIN re_kunden ON rechnung.ID = re_kunden.ID_rechnung
WHERE rechnung.ID LIKE re_kunden.ID_rechnung
GROUP BY ???TODAY???(rechnung.datum)

数据

+----+-------------+----------+------------+-------------+---------+
| ID | rechnungsnr | kundennr |   datum    | lieferdatum | bezahlt |
+----+-------------+----------+------------+-------------+---------+
| 10 |       10010 |     1003 | 2018-12-09 | 2018-12-10  |       1 |
| 11 |       10009 |     1005 | 2018-12-09 | 2018-12-10  |       1 |
| 12 |       10011 |     1001 | 2018-12-10 | 2018-12-10  |       1 |
| 13 |       10054 |     1004 | 2018-12-10 | 2018-12-10  |       1 |
+----+-------------+----------+------------+-------------+---------+

和数据

+----+-------------+----------+-------------+-------+----------+--------+--------+------+
| ID | ID_rechnung | position | bezeichnung | menge | einheit  | epreis | gpreis | text |
+----+-------------+----------+-------------+-------+----------+--------+--------+------+
|  1 |          10 |        1 | text        |     1 | text     |      1 |      1 | text |
|  2 |          11 |        1 | text        |     2 | text     |      1 |      2 | text |
|  3 |          12 |        1 | text        |     3 | text     |      1 |      3 | text |
|  4 |          13 |        1 | text        |     1 | text     |      1 |      1 | text |
+----+-------------+----------+-------------+-------+----------+--------+--------+------+

1 个答案:

答案 0 :(得分:0)

您可以在WHERE子句中尝试使用rechnung.datum = curdate()而不是GROUP BY,因为您只需要今天的记录。

  SELECT rechnung.*, re_kunden.*,  SUM(re_kunden.gpreis) as preise 
  FROM rechnung
     LEFT JOIN re_kunden ON rechnung.ID = re_kunden.ID_rechnung
     WHERE rechnung.ID LIKE re_kunden.ID_rechnung
     AND rechnung.datum = curdate()