標籤:尋找 sql語句 creat 一個 ifnull order by 內容 data 表名
1.資料的匯入
建立資料庫;
Select version();//查看當前資料庫版本(假如資料庫升級,加了-s,沒有對原資料進行重構,只對系統資料表進行了重構,那麼資料庫的版本可能不是當前的版本);
Create database 資料庫名稱;//建立資料庫
Show databases ; //顯示所有的資料庫,產看錶是否已經匯入
Use 剛剛建立的資料庫;
Source 需要匯入的表(檔案名稱);//匯入表
Show tables ;//顯示該庫下的表
Desc 原表名(不是檔案名稱);//顯示表的結構
Select * from 表名; //查看錶內容
2.資料庫及表的建立以及刪除
資料庫的建立
Create database 資料庫名稱;//建立資料庫
資料庫的刪除
drop database 資料庫名;
表
Create table 表名(
欄位1 修飾(範圍,這個是所有的都有範圍)
)
刪除表
Drop table 表名;
3.資料庫及表的查詢
資料庫
Show databases ; 查詢所有的表
show databases like ‘%es%’ ;//模糊尋找過濾;
select database(); 查看當前處於哪個資料庫;
表
Use test ;//使用庫
Show tables ;//顯示該庫下的所有表
show tables like ‘%es%’;//在資料庫test下模糊尋找具有es欄位的表;
show create table 表名 ;//查看怎麼建立的表
4.mysql的退出
Quit, exit , ctrl +c
5.select 語句
Select 欄位1,欄位2... from 表名 //查詢表中所有的欄位1,欄位2...資訊
Select 欄位1,欄位2... from 表名 where 條件 ;//查詢表中合格欄位1,欄位2...資訊
例如select name ,age from employee where name> 35 ;// 查詢表中age大於35的name age的資訊;
對select可進行如下一些操作
算術運算子
+,-,*,/,%
例如:
select salary*12 as ‘年薪’ from employees ; //as 輸出顯示的別名,可以省略不寫,其它運算子類似。
select salary*12 as ‘年薪’ from employees where salary>10000*3;
關係運算子
==,>,</>=,<=,!=,between a and b
例如: select salary from employees where salary>10000; // 其它類似;
select salary from employees where salary between 1000 and10000;
排序
oder by 【數字/欄位名】【asc/desc】,數字/欄位名】【asc/desc】
例如:select name from employees order by 1 asc;//1表示第一個欄位
select name salary from employees order by 1 asc;2 desc//按照那麼升序,salary降序;
is null , in ,not ,like
select name from employees where name in(‘張三’,‘李四’);//是張三或者李四
select name from employees where name is null;//null 表示什麼都沒有
select name from employees where name like ‘%s_s%’;//模糊尋找,%代表一個或者多個字元,_代表一個字元
select name from employees where name not in(‘張三’,‘李四’);//不是張三或者李四
select name from employees where name is not null;//表示不是null
資料處理函數
trim,upper,lower,substr(被處理欄位,下標,長度),length,round,rand,ifnull(欄位,如果為空白的預設值);
mysql(2)sql語句的入門