重复列0

时间:2014-04-30 03:51:28

标签: mysql sql

INSERT INTO KATH_USERS_VISITS (USERID, PLACEID, UTCTIME,WEEKDAY,HOUR, DURATION, NEXT_ID ) 
SELECT * FROM ( SELECT 9 , 5, '0' , 0 , 0 , 458.44000000000005 , 40 ) AS tmp 
WHERE NOT EXISTS (
                    SELECT 1 
                    FROM KATH_USERS_VISITS 
                    WHERE USERID=9 
                    and PLACEID=5 
                    and UTCTIME='0' 
                    and WEEKDAY=0 
                    and HOUR=0 
                    and DURATION=458.44000000000005 
                    and NEXT_ID=40 ) 
LIMIT 1;

当我尝试运行此查询时,它会给出一个错误,即复制第0列,我想检查记录是否不存在然后插入值。

1 个答案:

答案 0 :(得分:0)

您应该为列添加一些名称。

这样的东西
SELECT  *   
FROM    ( 
            SELECT  9 Col0, 
                    5 Col1, 
                    '0' Col2, 
                    0 Col3, 
                    0 Col4, 
                    458.44000000000005 Col5, 
                    40 Col6
        ) AS tmp 

SQL Fiddle DEMO