我有一个MSSQL查询,并希望将其转换为MySQL版本。但是我的控制台出错:
#1064 - 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 'DECLARE @selectedTags TABLE (ID int) DECLARE @tagCount int INSER' at line 1
我的代码如下:
DECLARE @selectedTags TABLE (ID int)
DECLARE @tagCount int
INSERT INTO @selectedTags VALUES (1)
INSERT INTO @selectedTags VALUES (3)
INSERT INTO @selectedTags VALUES (5)
SELECT @tagCount = COUNT(*) FROM @selectedTags
SELECT
P.ID
FROM Product P
JOIN ProductTag PT
ON PT.ProductID = P.ID
JOIN @selectedTags T
ON T.ID = PT.TagID
GROUP BY
P.ID,
P.Name
HAVING COUNT(PT.TagID) = @tagCount
答案 0 :(得分:0)
Mysql中没有TABLE类型,你必须CREATE TEMPORARY TABLE并插入它。
仅在存储的例程中允许DECLARE 设置@tagCount只需使用
SELECT COUNT(*) INTO @tagCount FROM temp_table;