• PHP MYSQL 临时表的使用


    /**
             * 临时表:用于获取爱鸽登录分类数量
             */
            $temporaryTableName = uniqid('temporary_');
            $model = M();
            $model->execute("CREATE TEMPORARY TABLE `{$temporaryTableName}` (
                `id` int unsigned,
                `leixing` tinyint(3) unsigned,
                `dangqianzhuangtai` tinyint(3) unsigned
            );");
            /**
             * dangqianzhuangtai
             * 1 - 存棚
             * 2 - 转让
             * 3 - 丢失
             * 4 - 死亡
             * 5 - 外借
             */
            $model->execute("INSERT INTO `{$temporaryTableName}`(`id`,`leixing`,`dangqianzhuangtai`) SELECT `id`,`leixing`,IF(`dangqianzhuangtai` IS NULL OR `dangqianzhuangtai` = '','0',`dangqianzhuangtai` ) FROM `mis_auto_hxwyg` WHERE `yonghu` = '1447'");
    
            // return $model->query("SELECT * FROM `{$temporaryTableName}`");
            $data['num1'] = $model->query("SELECT * FROM (SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '1' and `dangqianzhuangtai` = '1') AS `b`");
            $data['num2'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '1' and `dangqianzhuangtai` = '2'");
            $data['num3'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '1' and `dangqianzhuangtai` = '3'");
            $data['num4'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '1' and `dangqianzhuangtai` = '4'");
            $data['num5'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '1' and `dangqianzhuangtai` = '5'");
            
            $data['num6'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '2' and `dangqianzhuangtai` = '1'");
            $data['num7'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '2' and `dangqianzhuangtai` = '2'");
            $data['num8'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '2' and `dangqianzhuangtai` = '3'");
            $data['num9'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '2' and `dangqianzhuangtai` = '4'");
            $data['num10'] = $model->query("SELECT COUNT(*) AS `count` FROM `{$temporaryTableName}` WHERE `leixing` = '2' and `dangqianzhuangtai` = '5'");
            return $data;
  • 相关阅读:
    xp_cmdshell
    常用SQL语句
    SQL Server Select的递归查询-交叉表
    Sql Server 2005 行转列的实现(横排)
    sql导入导出
    使用正则表达式验证手机号、车牌号
    页面功能:设为首页和加入收藏
    两个文本框同步输入
    最常用的200个JS代码
    .NET 获取时间
  • 原文地址:https://www.cnblogs.com/jiangxiaobo/p/8931405.html
Copyright © 2020-2023  润新知