0
SELECT p.Producttype, pp.ProductID, r.Date1, r.Date2
FROM customers AS c
INNER JOIN orders AS r ON c.Cusid = r.Cusid
INNER JOIN temporary AS temp ON r.Cusid = temp.Cusid
INNER JOIN products AS pp ON pp.ProductID = temp.ProductID
INNER JOIN Producttypes AS p ON p.Producttypeid = pp.Producttypeid
WHERE temp.Cusid =  '23'
GROUP BY pp.ProductID

请帮助我不知道还能做什么,查询每次将第一行返回到列 date1 和 date2

4

1 回答 1

0

这是 MySql 的一个已知问题。它将允许在没有任何非分组字段的聚合函数的情况下进行分组。

它以其默认行为返回 group-by 之外的所有字段的第一个聚合。看到这个:为什么 MySQL 允许没有聚合函数的“group by”查询?没有聚合功能的 GROUP BY 子句有什么原因吗

删除该Group By条款,你应该没问题。

SELECT p.Producttype, pp.ProductID, r.Date1, r.Date2
FROM customers AS c
INNER JOIN orders AS r ON c.Cusid = r.Cusid
INNER JOIN temporary AS temp ON r.Cusid = temp.Cusid
INNER JOIN products AS pp ON pp.ProductID = temp.ProductID
INNER JOIN Producttypes AS p ON p.Producttypeid = pp.Producttypeid
WHERE temp.Cusid =  '23'
 --GROUP BY pp.ProductID -->This should be removed as it causes to returne the first of each other field while keeping ProductID distinct in the returned table.
于 2013-04-25T02:54:20.287 回答