你发我的上一个sql,报错Unknown table 'comment_sku_info' in MULTI DELETE
时间: 2024-09-18 22:10:54 浏览: 37
看起来你在尝试使用`MULTI DELETE`语句,这在MySQL中并不直接支持。`MULTI DELETE`在某些数据库系统如Oracle中有,但在MySQL中,如果要在一次查询中同时删除多行,应该使用标准的`DELETE`语句配合联接(`JOIN`)或其他方法,例如之前提供的`WITH`子查询的方式。
如果你是在MySQL环境下,那么正确的做法是像下面这样删除数据:
```sql
DELETE csi1
FROM comment_sku_info csi1
INNER JOIN (
WITH redundant_combinations AS (
SELECT platform_id, sku_url_id
FROM comment_sku_info
WHERE platform_id IN (...)
AND sku_url_id IN (...)
) SELECT * FROM redundant_combinations
) rc ON csi1.platform_id = rc.platform_id AND csi1.sku_url_id = rc.sku_url_id;
```
这里,我们先创建了一个包含冗余组合的内部查询`redundant_combinations`,然后用它去匹配`comment_sku_info`表里的对应行进行删除。
请注意,你需要替换`(...)`内的SQL子查询,以提供实际的`platform_id`和`sku_url_id`筛选条件。
相关问题
使用join优化 CREATE TEMPORARY TABLE t_sku_analyze_temp ( sku VARCHAR(225) PRIMARY KEY, sell_price DECIMAL(10, 2), profit DECIMAL(10, 2), sku_cost DECIMAL(10, 2), INDEX idx_sku (sku) ) ENGINE=InnoDB SELECT sku, SUM(daily_sell_price) AS sell_price, SUM(profit) AS profit,sum(sku_cost) as sku_cost, FROM t_sku_analyze2023 WHERE statistics_time >= '2023-04-01 00:00:00' AND statistics_time <= '2023-04-30 00:00:00' GROUP BY sku; CREATE TEMPORARY TABLE t_sku_refund_temp ( sku VARCHAR(225) PRIMARY KEY, refund_monry DECIMAL(10, 2), INDEX idx_sku (sku) ) ENGINE=InnoDB SELECT sku, SUM(refund_monry) AS refund_monry FROM t_sku_refund_analysis2023 WHERE refund_month = '2023-04' GROUP BY sku; SELECT t3.sku,sell_price,profit,refund_monry FROM t_sku_analyze_temp t3 LEFT JOIN t_sku_refund_temp t4 ON t3.sku = t4.sku; GROUP BY sku
Here is the optimized query using JOIN:
SELECT
t1.sku,
SUM(t1.daily_sell_price) AS sell_price,
SUM(t1.profit) AS profit,
SUM(t1.sku_cost) AS sku_cost,
SUM(t2.refund_monry) AS refund_monry
FROM t_sku_analyze2023 t1
LEFT JOIN t_sku_refund_analysis2023 t2 ON t1.sku = t2.sku AND t2.refund_month = '2023-04'
WHERE t1.statistics_time >= '2023-04-01 00:00:00' AND t1.statistics_time <= '2023-04-30 00:00:00'
GROUP BY t1.sku;
In this query, we combine the two temporary tables into a single query using a LEFT JOIN. We also move the WHERE clause to the main query to filter the data before joining, which can improve performance. Finally, we use SUM() functions to calculate the aggregate values instead of creating temporary tables.
ALTER TABLE `platform_plus`.`mall_goods_sku` MODIFY COLUMN `deposit_price` decimal(10, 2) NULL DEFAULT 0 COMMENT '定金' AFTER `cloud_merchant_ids` > 1054 - Unknown column 'deposit_price' in 'mall_goods_sku' > 时间: 0.016s
根据你提供的信息,可能是在执行这个 SQL 语句时出现了错误,提示了 `mall_goods_sku` 表中不存在 `deposit_price` 这个列。可能是因为这个列名拼写错误或者确实没有这个列。你可以检查一下数据库中 `mall_goods_sku` 表的列名是否正确,或者尝试执行 `DESC mall_goods_sku` 命令来查看该表的具体结构。
阅读全文