A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 梦想的小草 中级黑马   /  2016-9-2 21:42  /  430 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

SQL 语句:
        1.排序:
        select * from zhangwu where ... order by 字段名 [asc(升序,可以不写)/desc(降序)];
        2.聚合函数
            1).count():汇总行数;
            2).sum():某列数据求和;
            3).max():某列数据求最大;
            4).min():某列数据求最小;
            5).avg():某列数据求平均;
        3.分组:
            1).group by子句:
                select name,sum(money) from zhangwu where ... group by 字段名[,字段2,...];
                注意:如果是分组语句,select后面出现的列,要么是"聚合函数的结果",要么是"分组列";
            2).having子句:对聚合的结果进行筛选(where子句不能对聚合结果进行筛选)
                select name,sum(money) from zhangwu where sum(money) > 1000 group by name;//错误的
                正确的:
                select name,sum(money) from zhangwu group by name having sum(money) > 1000;//OK的

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马