MySQL(1)

数据库sql文件提取链接:https://pan.baidu.com/s/1wYa5N9tffL43EKWcg1dE7A?pwd=1010

提取码:1010

1. 列的别名

as:全称:alias(别名),可以省略

列的别名可以使用一对""引起来,不要使用''。

复制代码
SELECT employee_id emp_id,last_name AS lname,department_id "部门id",salary * 12 AS "annual sal"FROM employees;

2. 去除重复行

#查询员工表中一共有哪些部门id呢?

复制代码
SELECT DISTINCT department_idFROM employees;SELECT COUNT(DISTINCT department_id)FROM employees;

3. 空值参与运算

1. 空值:null

2. null不等同于0,'','null'

复制代码
SELECT * FROM employees;

#空值参与运算:结果一定也为空。

复制代码
SELECT employee_id,salary "月工资",salary * (1 + commission_pct) * 12 "年工资",commission_pctFROM employees;

#实际问题的解决方案:引入IFNULL​​​​​​​

复制代码
SELECT employee_id,salary "月工资",salary * (1 + IFNULL(commission_pct,0)) * 12 "年工资",commission_pctFROM `employees`;

4. 查询常数​​​​​​​

复制代码
SELECT '尚硅谷',123,employee_id,last_nameFROM employees;

5.显示表结构​​​​​​​

复制代码
DESCRIBE employees; DESC employees;DESC departments;

6.过滤数据

#练习:查询90号部门的员工信息

复制代码
SELECT * FROM employees WHERE department_id=90;

#练习:查询last_name为'King'的员工信息

复制代码
SELECT * FROM employees WHERE last_name='King';
相关推荐
k↑12 分钟前
微服务之注册中心与ShardingSphere关于分库分表的那些事
数据库·微服务·架构·shardingsphere
sleetdream13 分钟前
Flink Sql 按分钟或日期统计数据量
sql·flink
柏油1 小时前
MySQL 字符集 utf8 与 utf8mb4
数据库·后端·mysql
我科绝伦(Huanhuan Zhou)2 小时前
异构数据库兼容力测评:KingbaseES 与 MySQL 的语法・功能・性能全场景验证解析
数据库·mysql
Apple_羊先森2 小时前
Oracle数据库操作深入研究:备份、数据删除与性能优化
数据库·oracle·性能优化
一宿君3 小时前
Github 9 个惊艳的开源 NL2SQL 项目
sql·nlp·github
xiao-xiang11 小时前
redis-保姆级配置详解
数据库·redis
白鹭12 小时前
MySQL(多表查询练习)
数据库·mysql
吃掉你也没关系吧15 小时前
【postgresql】一文详解postgresql中的统计模块
sql·postgresql