我有一个包含客户数据和发票的小型 LibreOffice 数据库。每张发票由 n 个项目组成。
顾客:
**********************
* ID * Name * Adress *
**********************
* 0 * N1 * A1 *
* 1 * N2 * A2 *
**********************
发票:
********************************
* ID * CustomerID * Date *
********************************
* 0 * 0 * 01/01/1970 *
* 1 * 0 * 08/02/1971 *
********************************
项目:
***********************************
* ID * InvoiceID * Amount * Price *
***********************************
* 1 * 0 * 12 * 12.95 *
* 2 * 0 * 9 * 8.75 *
* 3 * 1 * 29 * 8.75 *
***********************************
我想用发票的价值创建一个查询:
SELECT "invoices"."ID", SUM( "items"."Amount" * "items"."Price" )
FROM "invoices", "items"
WHERE "invoices"."ID" = "items"."InvoiceID"
GROUP BY "invoice"."ID"
到目前为止一切正常。但是,如果我想在查询中包含更多信息,例如
SELECT "invoices"."ID", "invoices"."Date", SUM( "items"."Amount" * "items"."Price" )
FROM "invoices", "items"
WHERE "invoices"."ID" = "items"."InvoiceID"
GROUP BY "invoice"."ID"
我收到错误消息Not in aggregate function or group by clause
。我在 phpmyadmin 中尝试过它并且它有效,所以我认为 SQL 语法应该没问题。我的 SQL 语句有什么问题?