首页 > 数据库技术 > 详细

sql not exsit

时间:2015-07-27 10:45:46      阅读:529      评论:0      收藏:0      [点我收藏+]
        //check the adConsumed table to find whether the same status, status ‘1‘ is in the table, 
        //if the status exsits in the table do not insert that row
        //if the status does not exsit in the table insert the row
        //col2 is the advertisementID calculated from the appinfo with appid
        $sql = ‘INSERT INTO adConsumed(customerID, advertisementID, consumedStatus, consumedTime) 
                select col1, col2, col3, col4
                from (select :customerID as col1, (SELECT `advertisementID` FROM `appInfo` WHERE `ID`= :appid) as col2, 1 as col3, :time as col4) t
                WHERE NOT EXISTS (SELECT * FROM adConsumed WHERE customerID = :customerID and advertisementID = col2 and consumedStatus=1)‘;

        $command = $connection->createCommand($sql);
        $command->bindParam(‘:appid‘, $appid);
        $command->bindParam(‘:customerID‘, $customerID);
        $command->bindParam(‘:time‘, date(‘Y-m-d H:i:s‘));
        $updateSucceeded = $command->execute();

 sql 语句中包含sql语句.

 

sql not exsit

原文:http://www.cnblogs.com/wlemory/p/4679464.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!