SQL語句,資料庫增加、刪除、修改、查詢
阿新 • • 發佈:2020-12-10
1. 查詢表中的全部資料
select * from table;
2. 查詢某幾列資料
select column1, column2 from table;
3. 查詢某一列不同值
select distinct column from table;
4. 過濾篩選
-
根據某一列的值查詢
select * from table1 where colume1='XXX';
-
範圍查詢
select * from table1 where colume1 > 2000 and colume1 < 3000;
-
滿足不包含條件的值
select * from table1 where not colume1 > 1500;
-
空值判斷 is null
select * from table1 where colume1 is null;
-
between and(包含上下限)
select * from table where colume between 1500 and 3000;
-
In 查詢列中等於某一項的值
select * from table1 where colume1 in (100,200,500);
-
模糊查詢
select * from table1 where colume1 like 'M%'; #M 為要查詢內容中的模糊資訊。 #% 表示多個字值,_ 下劃線表示一個字元; #M% : 為能配符,正則表示式,表示的意思為模糊查詢資訊為 M 開頭的。 #%M% : 表示查詢包含M的所有內容。 #%M_ : 表示查詢以M在倒數第二位的所有內容。
5. AND 和 OR
- 如果第一個條件和第二個條件都成立,則 AND 運算子顯示一條記錄。
- 如果第一個條件和第二個條件中只要有一個成立,則 OR 運算子顯示一條記錄。
6. ORDER BY
- ORDER BY 關鍵字預設按照升序對記錄進行排序。如果需要按照降序對記錄進行排序,您可以使用 DESC 關鍵字
SELECT COLUME1 FROM TABLE1 ORDER BY COLUME1;
7. 插入
-
插入一行,需要values中寫全所有屬性
Insert into table1 values (values1,values2,......)
-
指定列插入資料,id會自動更新,沒指定的列會是預設值或者null。
Insert into table(colume1,cloume3,cloume6) values('aaa','1234','dvvdfv');
8. 更新(修改)
注意: set 使用
,
逗號分割。
update table1 set colume1=value1,colume2=value2,..... where colume5=value5;
9. 刪除
Delete from table1 where colume1=value1;
轉自: https://blog.csdn.net/hongdunyang/article/details/86181589