pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <legend id='SL8fg'><style id='SL8fg'><dir id='SL8fg'><q id='SL8fg'></q></dir></style></legend>
    <i id='SL8fg'><tr id='SL8fg'><dt id='SL8fg'><q id='SL8fg'><span id='SL8fg'><b id='SL8fg'><form id='SL8fg'><ins id='SL8fg'></ins><ul id='SL8fg'></ul><sub id='SL8fg'></sub></form><legend id='SL8fg'></legend><bdo id='SL8fg'><pre id='SL8fg'><center id='SL8fg'></center></pre></bdo></b><th id='SL8fg'></th></span></q></dt></tr></i><div class="frpop3p" id='SL8fg'><tfoot id='SL8fg'></tfoot><dl id='SL8fg'><fieldset id='SL8fg'></fieldset></dl></div>
  1. <small id='SL8fg'></small><noframes id='SL8fg'>

  2. <tfoot id='SL8fg'></tfoot>
      <bdo id='SL8fg'></bdo><ul id='SL8fg'></ul>

      Yii:獲取每月熱門用戶和年末熱門用戶的SQL查詢

      Yii: SQL query for getting the top users for every month and top users at the end of year(Yii:獲取每月熱門用戶和年末熱門用戶的SQL查詢)
    1. <legend id='AGdLL'><style id='AGdLL'><dir id='AGdLL'><q id='AGdLL'></q></dir></style></legend>

      <small id='AGdLL'></small><noframes id='AGdLL'>

      1. <tfoot id='AGdLL'></tfoot>

          <i id='AGdLL'><tr id='AGdLL'><dt id='AGdLL'><q id='AGdLL'><span id='AGdLL'><b id='AGdLL'><form id='AGdLL'><ins id='AGdLL'></ins><ul id='AGdLL'></ul><sub id='AGdLL'></sub></form><legend id='AGdLL'></legend><bdo id='AGdLL'><pre id='AGdLL'><center id='AGdLL'></center></pre></bdo></b><th id='AGdLL'></th></span></q></dt></tr></i><div class="ucr3s8y" id='AGdLL'><tfoot id='AGdLL'></tfoot><dl id='AGdLL'><fieldset id='AGdLL'></fieldset></dl></div>

              <bdo id='AGdLL'></bdo><ul id='AGdLL'></ul>

                <tbody id='AGdLL'></tbody>
                本文介紹了Yii:獲取每月熱門用戶和年末熱門用戶的SQL查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我是一個 yiibie,我有一個問題,我有一個名為 user_join_event 的表,它有 id(PK) ngo_id(FK) event_id(FK) date_created date_modified 作為對象,我想獲得每個月的 5 個用戶 ID(在此表中重復次數最多).像1月前5名用戶,2月前5名用戶等等,然后是這張表中年底前5名的用戶,就像一年結束后,它應該再次給出整個月的前5名用戶.請幫我解決這個問題,如何為此編寫SQL查詢,謝謝.

                 公共函數 actionAllstats(){$this->layout='main';$user=UserJoinEvent::model()->findAll(array('條件' =>'YEAR(date_created)=:year 和 MONTH(date_created)=:month','參數' =>數組(':year'=>2015, ':month'=>$yourMonth),'選擇'='=>'user_id','組'=>'user_id','訂單'=>'COUNT(*) DESC','限制' =>5));$this->render('allstats', array("user"=>$user));}

                這是我的視圖文件

                <?phpforeach($user 作為 $show){for($i = 1 ; $i <=12 ; $i++){if($yourMonth == $i){$model = User::model()->findByAttributes(array('id'=>$show->user_id,));如果(isset($模型)){回聲'<h3>'.$show->user_id .' - ' .$model->用戶名.'</h3>';}別的 {回聲'<h3>'.$show->user_id .' - 未找到用戶名</h3>';}}}}?>

                解決方案

                你可以起訴這個查詢獲得用戶的年度

                 $user=UserJoinEvent::model()->findAll(array('條件' =>'YEAR(date_create)=:year','參數' =>數組(':year'=>2015)'選擇'='=>'user_id','組'=>'user_id','訂單'=>'COUNT(*) DESC','限制' =>5));

                并且對于這個月,您可以使用此查詢從 1 到 12 進行循環,并使用循環中的值設置 $yourMonth

                 $user=UserJoinEvent::model()->findAll(array('條件' =>'YEAR(date_create)=:year 和 MONTH(date_create)=:month','參數' =>數組(':year'=>2015, ':month'=>$yourMonth)'選擇'='=>'user_id','組'=>'user_id','訂單'=>'COUNT(*) DESC','限制' =>5));

                控制器動作

                公共函數 actionAllstats(){$this->layout='main';$myCurrYear = 日期(Y")$userYear=UserJoinEvent::model()->findAll(array('條件' =>'YEAR(date_create)=:year','參數' =>數組(':year'=>$myCurrYear)'選擇'='=>'user_id','組'=>'user_id','訂單'=>'COUNT(*) DESC','限制' =>5));$this->render('allstats', array("userYear"=>$userYear));}

                查看

                這個視圖不是基于良好的實踐,因為在視圖中使用了對模型的訪問.是為了引導您了解與問題相關的一些問題的嘗試.

                <?php//這十二個月for($month = 1 ; $month <=12 ; $month++) {<div>$user=UserJoinEvent::model()->findAll(array('條件' =>'YEAR(date_created)=:year 和 MONTH(date_created)=:month','參數' =>數組(':year'=>2015, ':month'=>$month),'選擇'='=>'user_id','組'=>'user_id','訂單'=>'COUNT(*) DESC','限制' =>5));foreach($user as $show) {$model = User::model()->findByAttributes(array('id'=>$show->user_id,));如果(isset($模型)){回聲'<h3>'.$show->user_id .' - ' .$model->用戶名.'</h3>';}別的 {回聲'<h3>'.$show->user_id .' - 未找到用戶名</h3>';}}

                }?><div><?php//年份foreach($userYear as $show) {$model = User::model()->findByAttributes(array('id'=>$show->user_id,));如果(isset($模型)){回聲'<h3>'.$show->user_id .' - ' .$model->用戶名.'</h3>';}別的 {回聲'<h3>'.$show->user_id .' - 未找到用戶名</h3>';}}?>

                I am a yiibie, I have a question that I have a table named user_join_event which has id(PK) ngo_id(FK) event_id(FK) date_created date_modified as objects, and I want to get the 5 users Id's(which are repeated the most in this table) for every month. Like January top 5 users, Feb top 5 users and so on and then the top 5 users at the end of the year from this table, like once the year is completed it should give again the top 5 users from all over the month. Please help me with this, how to write an SQL query for this, thank you.

                 public function actionAllstats()
                            {
                
                        $this->layout='main';
                        $user=UserJoinEvent::model()->findAll(array(
                            'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
                            'param' => array(':year'=>2015, ':month'=>$yourMonth),
                            'select'=>'user_id',
                            'group'=>'user_id',
                            'order'=>'COUNT(*) DESC',
                            'limit' =>  5
                         ));  
                        $this->render('allstats', array("user"=>$user));
                            }
                

                and this is my view file

                <div>
                    <?php
                
                        foreach($user as $show)
                        {
                            for($i = 1 ; $i <=12 ; $i++)
                            {
                                if($yourMonth == $i)
                                {
                                    $model = User::model()->findByAttributes(array('id'=>$show->user_id,));
                           if (isset($model)) 
                               {
                               echo '<h3>' . $show->user_id .  ' - ' . $model->username . '</h3>';
                           } 
                           else {
                               echo '<h3>' . $show->user_id .  ' - Username not found</h3>';
                           } 
                                }
                            }
                
                        }
                
                        ?>
                    </div>
                

                解決方案

                For the Year you can sue this query for getting the users

                       $user=UserJoinEvent::model()->findAll(array(
                            'condition' => 'YEAR(date_create)=:year',
                            'params' => array(':year'=>2015)
                            'select'=>'user_id',
                            'group'=>'user_id',
                            'order'=>'COUNT(*) DESC',
                            'limit' =>  5
                         ));  
                

                and for the month you can do a loop from 1 to 12 using this query and set $yourMonth withe the value in loop

                       $user=UserJoinEvent::model()->findAll(array(
                            'condition' => 'YEAR(date_create)=:year and MONTH(date_create)=:month',
                            'params' => array(':year'=>2015, ':month'=>$yourMonth )
                            'select'=>'user_id',
                            'group'=>'user_id',
                            'order'=>'COUNT(*) DESC',
                            'limit' =>  5
                         ));  
                

                Controller action

                public function actionAllstats()
                {
                
                    $this->layout='main';
                    $myCurrYear = date("Y")
                    $userYear=UserJoinEvent::model()->findAll(array(
                        'condition' => 'YEAR(date_create)=:year',
                        'params' => array(':year'=>$myCurrYear)
                        'select'=>'user_id',
                        'group'=>'user_id',
                        'order'=>'COUNT(*) DESC',
                        'limit' =>  5
                     ));  
                    $this->render('allstats', array("userYear"=>$userYear));
                }
                

                View

                This view in not based on good pratice, because use access to model inside a view. is a trial for lead you to understand some of the problem related with question.

                <?php    // this for the twelve month
                
                    for($month = 1 ; $month <=12 ; $month++) {
                    <div>
                        $user=UserJoinEvent::model()->findAll(array(
                            'condition' => 'YEAR(date_created)=:year and MONTH(date_created)=:month',
                            'params' => array(':year'=>2015, ':month'=>$month),
                            'select'=>'user_id',
                            'group'=>'user_id',
                            'order'=>'COUNT(*) DESC',
                            'limit' =>  5
                         ));    
                        foreach($user as $show) {
                            $model = User::model()->findByAttributes(array('id'=>$show->user_id,));
                            if (isset($model)) {
                                echo '<h3>' . $show->user_id .  ' - ' . $model->username . '</h3>';
                            } 
                             else {
                                echo '<h3>' . $show->user_id .  ' - Username not found</h3>';
                            } 
                        }
                    </div>            
                    }
                ?>
                
                
                <div>   
                    <?php // the for the year 
                        foreach($userYear as $show) {
                            $model = User::model()->findByAttributes(array('id'=>$show->user_id,));
                            if (isset($model)) {
                                echo '<h3>' . $show->user_id .  ' - ' . $model->username . '</h3>';
                            } 
                             else {
                                echo '<h3>' . $show->user_id .  ' - Username not found</h3>';
                            } 
                        }
                    ?>
                </div>
                

                這篇關于Yii:獲取每月熱門用戶和年末熱門用戶的SQL查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                SQL query to get all products, categories and meta data woocommerce/wordpress(獲取所有產品、類別和元數據的 SQL 查詢 woocommerce/wordpress)
                Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不編寫 SQL 查詢的情況下找出數據庫列表和 SQL Server 實例使用的空間嗎?) - IT屋-程序員軟件開發
                How to create a login to a SQL Server instance?(如何創建對 SQL Server 實例的登錄?)
                How to know the version and edition of SQL Server through registry search(如何通過注冊表搜索知道SQL Server的版本和版本)
                WinForms application design - moving documents from SQL Server to file storage(WinForms 應用程序設計——將文檔從 SQL Server 移動到文件存儲)
                How to use MySQL in WSL (Windows Subsystem for Linux)?(如何在 WSL(Linux 的 Windows 子系統)中使用 MySQL?)
                <legend id='qtAex'><style id='qtAex'><dir id='qtAex'><q id='qtAex'></q></dir></style></legend>
                  <bdo id='qtAex'></bdo><ul id='qtAex'></ul>
              • <i id='qtAex'><tr id='qtAex'><dt id='qtAex'><q id='qtAex'><span id='qtAex'><b id='qtAex'><form id='qtAex'><ins id='qtAex'></ins><ul id='qtAex'></ul><sub id='qtAex'></sub></form><legend id='qtAex'></legend><bdo id='qtAex'><pre id='qtAex'><center id='qtAex'></center></pre></bdo></b><th id='qtAex'></th></span></q></dt></tr></i><div class="furgc3f" id='qtAex'><tfoot id='qtAex'></tfoot><dl id='qtAex'><fieldset id='qtAex'></fieldset></dl></div>

                <tfoot id='qtAex'></tfoot>

                  1. <small id='qtAex'></small><noframes id='qtAex'>

                  2. 主站蜘蛛池模板: 超声波清洗机-超声波清洗设备定制生产厂家 - 深圳市冠博科技实业有限公司 | 苏州柯瑞德货架-仓库自动化改造解决方案 | 化工ERP软件_化工新材料ERP系统_化工新材料MES软件_MES系统-广东顺景软件科技有限公司 | 慈溪麦田广告公司,提供慈溪广告设计。 | 粉末包装机-给袋式包装机-全自动包装机-颗粒-液体-食品-酱腌菜包装机生产线【润立机械】 | 10吨无线拉力计-2吨拉力计价格-上海佳宜电子科技有限公司 | 儿童语言障碍训练-武汉优佳加感统文化发展有限公司 | 塑料异型材_PVC异型材_封边条生产厂家_PC灯罩_防撞扶手_医院扶手价格_东莞市怡美塑胶制品有限公司 | 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | 粘度计NDJ-5S,粘度计NDJ-8S,越平水分测定仪-上海右一仪器有限公司 | 高压贴片电容|贴片安规电容|三端滤波器|风华电容代理南京南山 | [品牌官网]贵州遵义双宁口腔连锁_贵州遵义牙科医院哪家好_种植牙_牙齿矫正_原华美口腔 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | 承插管件_不锈钢承插管件_锻钢高压管件-温州科正阀门管件有限公司 | 皮带机-带式输送机价格-固定式胶带机生产厂家-河南坤威机械 | 活性氧化铝球|氧化铝干燥剂|分子筛干燥剂|氢氧化铝粉-淄博同心材料有限公司 | 预制围墙_工程预制围墙_天津市瑞通建筑材料有限公司 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 高考志愿规划师_高考规划师_高考培训师_高报师_升学规划师_高考志愿规划师培训认证机构「向阳生涯」 | 航拍_专业的无人机航拍摄影门户社区网站_航拍网 | 锡膏喷印机-全自动涂覆机厂家-全自动点胶机-视觉点胶机-深圳市博明智控科技有限公司 | SMN-1/SMN-A ABB抽屉开关柜触头夹紧力检测仪-SMN-B/SMN-C-上海徐吉 | 液压油缸-液压站生产厂家-洛阳泰诺液压科技有限公司 | 加中寰球移民官网-美国移民公司,移民机构,移民中介,移民咨询,投资移民 | 上海公司注册-代理记账-招投标审计-上海昆仑扇财税咨询有限公司 上海冠顶工业设备有限公司-隧道炉,烘箱,UV固化机,涂装设备,高温炉,工业机器人生产厂家 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | 金属软管_不锈钢金属软管_巩义市润达管道设备制造有限公司 | 依维柯自动挡房车,自行式国产改装房车,小型房车价格,中国十大房车品牌_南京拓锐斯特房车 - 南京拓锐斯特房车 | 砍排机-锯骨机-冻肉切丁机-熟肉切片机-预制菜生产线一站式服务厂商 - 广州市祥九瑞盈机械设备有限公司 | 右手官网|右手工业设计|外观设计公司|工业设计公司|产品创新设计|医疗产品结构设计|EMC产品结构设计 | 算命免费_生辰八字_免费在线算命 - 卜算子算命网 | 湖南自考_湖南自学考试网| 巨野电机维修-水泵维修-巨野县飞宇机电维修有限公司 | 东莞压铸厂_精密压铸_锌合金压铸_铝合金压铸_压铸件加工_东莞祥宇金属制品 | 酒精检测棒,数显温湿度计,酒安酒精测试仪,酒精检测仪,呼气式酒精检测仪-郑州欧诺仪器有限公司 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 伺服电机_直流伺服_交流伺服_DD马达_拓达官方网站 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 北京律师咨询_知名专业北京律师事务所_免费法律咨询 | 桁架机器人_桁架机械手_上下料机械手_数控车床机械手-苏州清智科技装备制造有限公司 | 热回收盐水机组-反应釜冷水机组-高低温冷水机组-北京蓝海神骏科技有限公司 |