今天在处理股票数据的时候发现同一只股票的季频数据存在相同日期的数据,所以需要通过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)