我有一个简单的查询:
SELECT COUNT(ud.UserID), COUNT(DISTINCT ud.ProductID)
FROM users_data AS ud
JOIN products AS t ON t.ID = ud.ProductID
WHERE ud.UserID = '3'
结果是:
COUNT(ud.UserID) COUNT(DISTINCT ud.ProductID)
519 425
当我尝试包含在 while 或 for 循环中时:
DELIMITER //
SET @i = 0;
FOR i IN 1..10
DO SELECT COUNT(ud.UserID), COUNT(DISTINCT ud.ProductID)
FROM users_data AS ud
JOIN products AS t ON t.ID = ud.ProductID
WHERE ud.UserID = (i)
END FOR
//
除了:
Query executed OK, 0 rows affected.
还有什么我想念的吗?谢谢你。