0

我在以下内容中收到错误“SELECT top (20) L.load_Number”:

INSERT INTO Last_20_Loads 
SELECT        top (20) L.load_Number, count(b.Bales_Per_Hour) AS COUNT_Bales_Per_Hour, sum(b.Bales_Per_Hour) AS SUM_Bales_Per_Hour
FROM Loads AS L INNER JOIN
    Bales AS B ON L.Load_Number = B.Load_Number 
where (status = 7)
GROUP BY l.load_Number
ORDER BY l.load_Number DESC;

为什么我会出错。怎么修?

谢谢,

杰瑞

4

2 回答 2

1

MySQL 使用 LIMIT 而不是 TOP。您还应该在 INSERT 语句中指定列名

INSERT INTO Last_20_Loads (load_number, countbales, sumbales)
SELECT L.load_Number, count(b.Bales_Per_Hour) AS COUNT_Bales_Per_Hour, sum(b.Bales_Per_Hour) AS SUM_Bales_Per_Hour
FROM Loads AS L INNER JOIN
Bales AS B ON L.Load_Number = B.Load_Number 
where (status = 7)
GROUP BY l.load_Number
ORDER BY l.load_Number DESC
LIMIT 20;
于 2013-04-01T15:51:03.687 回答
0

的等价TOPLIMIT在 mysql 中。

INSERT INTO Last_20_Loads 
SELECT  L.load_Number, 
        count(b.Bales_Per_Hour) AS COUNT_Bales_Per_Hour, 
        sum(b.Bales_Per_Hour) AS SUM_Bales_Per_Hour
FROM    Loads AS L 
        INNER JOIN Bales AS B 
            ON L.Load_Number = B.Load_Number 
where   (status = 7)
GROUP   BY l.load_Number
ORDER   BY l.load_Number DESC
LIMIT   20;
于 2013-04-01T15:50:22.970 回答