查询mysql数据库表单和使用函数介绍
更新:HHH   时间:2023-1-7


下文主要给大家带来查询mysql数据库表单和使用函数,希望这些内容能够带给大家实际用处,这也是我编辑查询mysql数据库表单和使用函数这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。

单表查询

准备一张雇员表company.employee

雇员编号 emp_id   int

雇员姓名 emp_name  varchar(30)

雇员性别 sex  enum

雇用日期 hire_date  date

职位  post  varchar(50)

职位描述 job_description  varchar(50)

薪水 salary double(15,2)

办公室office int

部门编号 dep_id int

 

一、表的简单查询

Select * from employee;  //查看全部

Select 字段1,字段2,...字段n from 表名

避免重复关键字distinct

Select distinct post from employee

关系运算符:+ - * %

Select emp_name salary*12 from employee;

As别名

Select emp_name as姓名 salary*12 as 薪水 from employee;

定义显示格式 concat()函数用于连接字符串

Select concat (emp_name,annual salary ,salary*12) as 员工年薪

 From employee; 

二、通过条件查询

条件查询条件表达式

比较运算符:> <= != >= <=

逻辑运算符and 或者&&  or或者||  xor  not或者!

语法:select 字段1,字段2,字段N from 表名  where condition(条件表达式)

单条件查询

Select emp_name from employee where post =hr

多条件查询

Select emp_name from employee where post=hr and salayr>100000;

关键字查询between and     

Select emp_name from employee

Where salary between 5000 and 15000;  //工资在500015000之间

Select emp_name from employee

Where salary  not  between 5000 and 15000; //  工资不在500015000之间的人

关键字查询is  null

Select emp_name,job_description from employee

Where job_description is  null; // 查看职位描述是空的员工

Select emp_name,job_description from employee

Where job_description is not null; //查看职位描述非空的员工

 对于以上关于查询mysql数据库表单和使用函数,大家是不是觉得非常有帮助。如果需要了解更多内容,请继续关注我们的行业资讯,相信你会喜欢上这些内容的。

返回数据库教程...