mysql/mariadb学习记录——查询2
2018-06-18 01:24:29来源:未知 阅读 ()
Alias——使用一个列名别名AS 关键字:
mysql> select sno as studentId,sname as studentName from student; +-----------+-------------+ | studentId | studentName | +-----------+-------------+ | 12001 | bgg | | 96001 | 刘军 | | 95002 | 刘晨 | | 94001 | 山寨 | | 95005 | 张三 | | 95004 | 张立 | | 95001 | 李勇 | | 97001 | 李四 | | 95003 | 王敏 | | 96004 | 芙蓉 | +-----------+-------------+ 10 rows in set (0.10 sec) //在mysql/mariadb中省略as 关键字也可实现 mysql> select sno studentId,sname studentName from student; +-----------+-------------+ | studentId | studentName | +-----------+-------------+ | 12001 | bgg | | 96001 | 刘军 | | 95002 | 刘晨 | | 94001 | 山寨 | | 95005 | 张三 | | 95004 | 张立 | | 95001 | 李勇 | | 97001 | 李四 | | 95003 | 王敏 | | 96004 | 芙蓉 | +-----------+-------------+ 10 rows in set (0.07 sec)
GROUP BY语句:
比如在合计(sum函数)的时候常需要用group by语句来进行分类求和
//emp表格中的数据 mysql> select * from emp; +-------+--------+-----------+------+------------+---------+---------+--------+ | empno | ename | job | mgr | hiredate | sal | comm | deptno | +-------+--------+-----------+------+------------+---------+---------+--------+ | 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 | | 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 | | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 | | 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 | | 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 | | 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 | | 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 | | 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 | 3000.00 | NULL | 20 | | 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 | | 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 | | 7876 | ADAMS | CLERK | 7788 | 1987-05-23 | 1100.00 | NULL | 20 | | 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 | | 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 | | 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 | +-------+--------+-----------+------+------------+---------+---------+--------+ //查找每个job种类一共支出的sal是多少 mysql> select job,sum(sal) from emp group by job; +-----------+----------+ | job | sum(sal) | +-----------+----------+ | ANALYST | 6000.00 | | CLERK | 4150.00 | | MANAGER | 8275.00 | | PRESIDENT | 5000.00 | | SALESMAN | 5600.00 | +-----------+----------+ 5 rows in set (0.12 sec) //查看student表中的男女生人数 mysql> select ssex,count(sage) from student group by ssex; +------+-------------+ | ssex | count(sage) | +------+-------------+ | M | 1 | | 女 | 3 | | 男 | 6 | +------+-------------+
2018-05-01 23:21:52
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- MySQL replace函数怎么替换字符串语句 2020-03-09
- PHP访问MySQL查询超时怎么办 2020-03-09
- mysql登录时闪退 2020-02-27
- MySQL出现1067错误号 2020-02-27
- mysql7.x如何单独安装mysql 2020-02-27
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash