gpt4 book ai didi

mysql - MySQL 中的三个表连接计数

转载 作者:行者123 更新时间:2023-11-29 00:37:09 27 4
gpt4 key购买 nike

我这里有个问题;当我查询时:

SELECT product.*,product_description.*,COUNT(product_image.*) 
FROM " . DB_PREFIX . "product
INNER JOIN product_description ON product.product_id = product_description.product_id
INNER JOIN product_image ON product.product_id = product_image.product_id
ORDER BY product.date_modified DESC

我想为表 product_image 选择 3 表 n 1 计数,但出现此错误:

Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') FROM product INNER JOIN product_description ON product.product_id = product_' at line 1 Error No: 1064 SELECT product.,product_description.,COUNT(product_image.) FROM product INNER JOIN product_description ON product.product_id = product_description.product_id INNER JOIN product_image ON product.product_id = product_image.product_id ORDER BY product.date_modified DESC

最佳答案

您不应该像这样使用COUNT 函数。 COUNT(TableName.*) 连接表时。您需要像这样使用它的任何列 COUNT(TableName.ColumnName)

例如COUNT(product_image.ID)

See this SQLFiddle

关于mysql - MySQL 中的三个表连接计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13720497/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com