如何在MySQL

时间:2017-10-10 11:57:49

标签: mysql

以下是我的SELECT查询:

SELECT Data.VendorProductRateID    
FROM
(SELECT MIN(VendorProductRateID) VendorProductRateID
FROM TMP_VendorProductRate
WHERE VendorProductID = 4
  AND VendorProductRateTxnInfoID = 89
GROUP BY DialCode,StartTime) Data,
TMP_VendorProductRate TMP_VendorProductRate
WHERE (TMP_VendorProductRate.VendorProductRateID = Data.VendorProductRateID);

结果:

VendorProductRateID
123
124
125

我的表有50条记录,所以现在我要删除所有记录而不超过3个ID。

我尝试使用以下查询但无法删除记录:

DELETE FROM `TMP_VendorProductRate` AS CHC  WHERE CHC.VendorProductRateID NOT IN
(
    SELECT Data.VendorProductRateID
    FROM
        (SELECT MIN(VPR.VendorProductRateID) VendorProductRateID
            FROM TMP_VendorProductRate VPR
            WHERE VPR.VendorProductID = 4
                AND VPR.VendorProductRateTxnInfoID = 90
            GROUP BY VPR.DialCode,VPR.StartTime
        ) 
    Data,
    TMP_VendorProductRate TMP_VendorProductRate
    WHERE (TMP_VendorProductRate.VendorProductRateID = Data.VendorProductRateID)
)

错误:#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在#CHC.VendorProductRateID NOT IN附近使用正确的语法 (     SELECT Data.VendorProductRa'在第1行

1 个答案:

答案 0 :(得分:0)

您可以在此处查看删除查询语法

https://www.w3schools.com/sql/sql_delete.asp

Regex.Replace(value, @"(\d)(\p{L})", "$1 $2")) 查询不会出现别名,如下所示,

DELETE

这可能会有所帮助

<强>更新

没有别名,你可以给,

DELETE FROM `TMP_VendorProductRate` WHERE...

试试这个......

另请告诉我DELETE FROM `TMP_VendorProductRate` WHERE VendorProductRateID NOT IN ( SELECT Data.VendorProductRateID FROM (SELECT MIN(VPR.VendorProductRateID) VendorProductRateID FROM TMP_VendorProductRate VPR WHERE VPR.VendorProductID = 4 AND VPR.VendorProductRateTxnInfoID = 90 GROUP BY VPR.DialCode,VPR.StartTime ) Data WHERE (TMP_VendorProductRate.VendorProductRateID = Data.VendorProductRateID) ) 这意味着什么?

相关问题