zoukankan      html  css  js  c++  java
  • mysql分组和排序操作

    分组、排序操作      
                                                                                    
     select * from student order by id desc,height asc;                                                         排序,mysql默认根据主键正序排列,order by 排序字段,asc正序,desc倒序,防止一个条件相同内容导致无法排序,再增加第二个排序条件进行排序       
                               
     select count(*),gender from student group by gender;                                                   group by分组,以gender分组,select与from之间为打印出来的内容,分别统计男、女人数                          
     
    select count(*),age from student where age = 20 group by age;                                  打印student表格里年龄为20的人数  
                                
     select count(*),age,group_concat(id) from student where age = 20 group by age;           
                          
     select gender,count(*) from student group by gender having count(*) > 3;                  student表格里以gender分组,打印gender与count个数,having必须跟group by使用,是在分组后二次筛选                          
     
    select * from student limit 1,2;                                                                                         limit限制 1:从第二个开始,取2个数据   
                                 
     select * from student order by rand() limit 1,2;                                                                order by rand()随机取数据         
                           
    select gender,count(*) from student group by gender with rollup;                                       以gender分组,gender和count,   with rollup累加count                                
     
  • 相关阅读:
    docker之Dockerfile实践
    使用dockerfile构建nginx镜像 转
    docker 批量删除含有同样名字的images
    redis扩展
    cocos2dx进阶学习之CCBI文件
    cocos2d-x游戏开发系列教程-超级玛丽09-怪物激活与移动
    cocos2d-x游戏开发系列教程-超级玛丽08-消息机制
    cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(六)-马里奥跳跃
    cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(五)-地图卷动
    cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(四)-马里奥平移
  • 原文地址:https://www.cnblogs.com/sunzhiqi/p/10072692.html
Copyright © 2011-2022 走看看