MySQL删除重复项——delete+groupby
mysql中delete语句今天在处理股票数据的时候发现同⼀只股票的季频数据存在相同⽇期的数据,所以需要通过delete+group来处理数据
1.在做多表查询,或者查询的时候产⽣新的表的时候会出现这个错误:Every derived table must have its own alias(每⼀个派⽣出来的表都必须有⼀个⾃⼰的别名)
当执⾏这条sql语句的时候就会出现Every derived table must have its own alias;
DELETE FROM `T_Security_MShare_StockHistoryAchieve`
WHERE ID in
(SELECT ID FROM
(SELECT ID FROM `T_Security_MShare_StockHistoryAchieve` where NVC_CODE='Y' GROUP BY DTM_INDEX_DATE))
2. 下⾯这条语句就会产⽣⼀张新的表,和前⾯的表stock联合查询,但是mysql要求每⼀个派⽣出来的表都必须有⼀个⾃⼰的别名,那我给派⽣表加上别名即可;
SELECT ID FROM `T_Security_MShare_StockHistoryAchieve` where NVC_CODE='Y' GROUP BY DTM_INDEX_DATE
eg:修改后的sql,直接在新⽣产的表中加⼊ 他的别命名就⾏(“as a”或者“a”),“a”为新表的别名
3.
DELETE FROM `T_Security_MShare_StockHistoryAchieve`
WHERE ID in
(SELECT ID FROM
(SELECT ID FROM `T_Security_MShare_StockHistoryAchieve` where NVC_CODE='Y' GROUP BY DTM_INDEX_DATE) As p)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论