SQL語句,數據庫增加、刪除、修改、查詢


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM