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;  //工资在5000到15000之间

Select emp_name from employee

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

关键字查询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; //查看职位描述非空的员工

本文转自    探花无情   51CTO博客,原文链接:http://blog.51cto.com/983865387/1917420

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值