天天看點

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之間

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

關鍵字查詢is  null

Select emp_name,job_description from employee

Where job_description is  null; // 檢視職位描述是空的員工

Where job_description is not null; //檢視職位描述非空的員工

本文轉自    探花無情   51CTO部落格,原文連結:http://blog.51cto.com/983865387/1917420