码迷,mamicode.com
首页 > 数据库 > 详细

sql not exsit

时间:2015-07-27 10:48:45      阅读:149      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!