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

posted @ 2020-12-10 21:33  公瑾当年  阅读(2039)  评论(0编辑  收藏  举报