sql基础语句

-- 插入一条数据(增)
-- insert into users (username,password)  values ("tony stark","098123")
-- insert into users set ?  -------------------------插入多条数据

-- 查询 所有的 数据 (查)
-- select * from users

--  将id为4的用户的密码更新为 8888  (改)
-- update users set password="888888" where id=4
  update users set ? where id=?  ----------------------更新多条数据


-- 更新id为2的用户,把用户的密码更新为admin123 同时把用户的状态更新为1  (改)
-- update users set password="admin123",status=1 where id=2 

--  删除 users表中id 为4的用户  删除的时候要 where的限定条件 
-- delete  from users where id=4

--  演示 where 子句的使用 
-- select *from users where status=1

-- 大于等于 
-- select *from users where id>=2

-- 不等于
-- select *from users where username !="ls"

-- and 检索 两个条件都要满足 
-- select * from users where status=0 and id<3

--  或检索 
-- select *from users where status=1 or username="zs"

--  升序排序
-- select * from  users order by status

-- 按照id 对结果进行降序的排序 desc 表示降序   asc 表示升序  默认升序  
-- select *from users order by id desc

-- 多重排序 状态降序  用户名 升序排序   
-- select  *from users  order by status desc,username asc  

-- 统计状态为 0 的 总数据条数
-- select count(*) from users where status=0

-- 使用 as 为列起别名 
-- select count(*)  as total from users where status=0
-- select username as uname ,password as pwd from users

-- 标记删除 (删)
--update users set status=1 where id=4
原文地址:https://www.cnblogs.com/ndh074512/p/14867721.html