本例所用库为mysql 表结果和数据类型在文章底部。
sql语句: 是数据库的核心语言
sql语句对表的填删改查操作:curd c creat(添加) u update(修改) r read(查询) d delete(删除)

查询: 在sql语句中 表名和字段加上加快sql语句的运行速度 (Tab键上面的那个键,英文状态下,打出来一对。读作:飘)。
select 字段,字段 from 表名
select id,username from emp 查询emp表中id和username字段
select * from emp 查询emp表中所有字段 * 代表所有(通配符,在css中是这么叫的,作用也是代表所有)。
select * from emp where id=1002 查询emp表中id等于1002的字段
select * from emp where id!=1002 查询emp表中id不等于1002的字段
select * from emp where id<>1002 查询emp表中id不等于1002的字段
select * from emp where id>1002 查询emp表中id大于1002的字段
select * from emp where id<1002 查询emp表中id小于1002的字段
select * from emp where id>=1002 查询emp表中id大于等于1002的字段
select * from emp where id in(1001,1004,1002) 查询emp表中 id的值在in里面的()的数据
select * from emp where id<=1002 查询emp表中id小于等于1002的字段
select * from emp where id not in(1001,1004,1002) 查询emp表中 id的值在in里面的()的数据
select * from emp where id between 1002 and 1004 查询emp表中 id的值在1002-1004之间的数据
select * from admin where name= ‘admin’ and pwd=‘admin123’ and 并且
select * from admin where name= ‘admin’ or pwd=‘admin123’ or 或者
select * from emp order by time desc 按照时间的降序排列 desc 降序 asc 升序
select * from emp where id in(1,2,3) order by time desc
如果有where条件 order by 必须放在where条件的后面
select * from emp limit 0,3 限制查询的条数 limit 起始位置,查询条数 第一条数据的位置是0
select * from ·emp· where ·id· in(1,3,4) order by iddesc limit 0,2
where order by limit 顺序不能乱
select count() from emp 查询表中总的数据条数
select count(
) as allnum from emp as取别名
select max(id) from emp 查询表中最大的id值
select min(id) from emp 查询表中最小的id值
select avg(id) from emp 查询表中id值的平均值
select sum(id) from emp 查询表中id值的和
添加:
insert into 表名 (字段,字段,字段) value (值1,值2 ,值3)
insert into admin (name,pwd) value (‘root’,‘root123’)

修改:
update 表名 set 字段=值1,字段=值2,字段=值3 where 条件
update ·admin· set name=user,pwd=user123 where id=2

删除:
delete from 表名 where 条件
delete from ``emp where id=4

SQL命令详解
SQL命令详解

SQL命令详解

SQL命令详解

相关文章:

  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2021-09-05
  • 2021-06-24
猜你喜欢
  • 2021-10-13
  • 2021-07-30
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
相关资源
相似解决方案