#通过四则运算查询 SELECT name, salary*12 FROM employee; SELECT name, salary*12 AS Annual_salary FROM employee; SELECT name, salary*12 Annual_salary FROM employee; 查看年薪salary*12 mysql> select name,salary*12 from employee; +------------+-------------+ | name |
创建数据库company create database company charset=utf8; use company; company.employee 员工id id int 姓名 emp_name varchar 性别 sex enum 年龄 age int 入职日期 hire_date date 岗位 post varchar 职位描述 post_comment varchar 薪水 salary double 办公室 office int 部门编号 depart_id int #
1. 查询岗位名以及岗位包含的所有员工名字 mysql> select post,group_concat(name) from employee group by post; +-----------+-------------------------------------------------+ | post | group_concat(name) | +-----------+-------------------------------------------------+ | o
1. 查询各岗位内包含的员工个数小于2的岗位名.岗位内包含员工名字.个数 mysql> select post,group_concat(name),count(id) from employee group by post; +-----------+-------------------------------------------------+-----------+ | post | group_concat(name) | count(id) | +-----------+-----
如果不指定排序 默认是按照id字段 从小到大排序的 升序 mysql> select * from employee; +----+------------+--------+-----+------------+-----------+--------------+------------+--------+-----------+ | id | name | sex | age | hire_date | post | post_comment | salary | office | de
一 单表查询的语法 select 字段1,字段2....from 表名 where 条件 group by field having 筛选 order by field limit 限制条数 二 关键字的执行优先级(重点) 关键字的执行优先级 from where group by having select distinct order by limit 1.找到表:from 2.拿着where指定的约束条件,去文件/表中取出一条条记录 3.将取出的一条条记录进行分组group by,如果没有
一 介绍 本节主题 多表连接查询 复合条件连接查询 子查询 准备表 #建表 create table department( id int, name varchar(20) ); create table employee( id int primary key auto_increment, name varchar(20), sex enum('male','female') not null default 'male', age int, dep_id int ); #插入数据 ins