SQL常用语句大全

1.插入数据

insert  into  表名(列1,列2,列3)values(值1,值2,值3);

insert  into product(name,price,pic_path) values(‘jack‘,25,‘updown‘);

2.更新数据

update  表名 set 列名1=值1,列名2=值2  where 条件;

update product set name="jack",price=35 where id=2;

3.删除数据库

delete from 表名[where 条件]

delete from product where id=2;

4.查询所有数据库内容

select * from 表名;

select * from product;

5.查询部分列

select 列1,列2 from 表名;

select id,name from product;

6.条件查询

#比较 =,>,<,>=,<=,!=

select * from 表名 where列名=值;

select * from product where id=2;

#and与

select * from 表名 where 条件1 and 条件2 and 条件3;

select * from product where id=2 and name=‘Nike‘;

#or 或

select * from 表名 where 条件1 or 条件2 or 条件3;

select * from product where name=‘Nike‘ or id=2;

#not 非

select * from 表名 where not 条件1;

select * from product where not name=‘Nike‘;

#in枚举

select * from 表名where 列名 in(值1,值2,值3);

select * from product where  id in(2,3,4,10);

select * from product where id not in(2,3,4);

#like模糊查询

select * from 表名where列名 like ‘%值%‘;

select * from product where name like ‘%LI%‘;

#between....and  范围查询

select * from 表名 where 列名 between 值1 and 值2;

select * from product where created between ‘2010-10-10‘ and ‘2011-10-10‘;

#limit行数查询

select * from 表名 limit  n1,n2;(n1:从第几行开始,从0开始算;n2:要显示几行)

select * from product limit 3,4;

7.查询排序

select * from 表名 order by列表排序方式。

#排序方式:asc(升序),desc(降序);

select * from product order by created desc;

8.聚合函数

#count 总记录数

select  count(列名) from student;

select count(id) from student;

#sum 总共

select  sum(列名) from student;

select sum(age) from student;

#avg  平均值

select avg(列名)from student;

select avg(age) from student;

#max  最大值

select max(列名)from student;

select max(age) from student;

#min  最小值

select  min(列名) from 表名;

select min(age) from student;

9.子查询

select name from student where age<(select avg(age) from student);

select * from product where id in(select id from order);

时间: 2024-08-09 09:18:24

SQL常用语句大全的相关文章

mysql sql常用语句大全

SQL执行一次INSERT INTO查询,插入多行记录 insert into test.person(number,name,birthday) values(5,'cxx5',now()),(6,'cxx6',now()),(7,'cxx7',now()); 1.说明:创建数据库 CREATE DATABASE database-name 2.说明:删除数据库 drop database dbname 3.说明:备份sql server --- 创建 备份数据的 device USE mas

SQL常用语法大全

一.基础1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数据的 deviceUSE masterEXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'--- 开始 备份BACKUP DATABASE pubs TO testBack 4.说明:创建新表create

MySQL 常用语句大全

MySQL 常用语句大全 一.连接 MySQL 格式: mysql -h 主机地址 -u 用户名 -p 用户密码 1.例 1:连接到本机上的 MYSQL. 首先在打开 DOS 窗口,然后进入目录 mysql bin,再键入命令 mysql -uroot -p,回 车后提示你输密码,如果刚安装好 MYSQL,超级用户 root 是没有密码的,故直接回车即 可进入到 MYSQL 中了,MYSQL 的提示符是: mysql>. 2.例 2:连接到远程主机上的 MYSQL.假设远程主机的 IP 为:11

SQL 常用语句

–-表现最差的前10名使用查询 SELECT TOP 10 ProcedureName = t.text, ExecutionCount = s.execution_count, AvgExecutionTime = isnull ( s.total_elapsed_time / s.execution_count, 0 ), AvgWorkerTime = s.total_worker_time / s.execution_count, TotalWorkerTime = s.total_wo

SQL常用语句积累

SQL 常用语句积累: 一. SQL 基本语句 SQL 分类: DDL -数据定义语言 (Create , Alter , Drop , DECLARE) DML -数据操纵语言 (Select , Delete , Update , Insert) DCL -数据控制语言 (GRANT , REVOKE , COMMIT , ROLLBACK) 首先 , 简要介绍基础语句: 1 .说明:创建数据库 Create DATABASE database-name 2 .说明:删除数据库 drop d

sql经典语句大全

SQL Server提供了大量的函数, 但是在一些常见的如, 字符串拆分, 字符提取,过滤等没有对应的处理, 本帖主要收集一些常见的函数, 整理如下: ------------------------------ http://topic.csdn.net/u/20080306/23/d3c100f2-cda1-4efa-927d-f1f7968884ce.html /* 功能:拆分字符串. 作者:..... */ http://topic.csdn.net/u/20080724/11/dacb

SQL常用语句集合(不断更新)

1.多条件 查询 上下级 所有数据 select * from OrgUnit where (ParentId = '3' or OrgId='3' or ParentId in (select OrgId from OrgUnit where ParentId='3')) 2.相同列数的 多个查询结果 组合(union all) select a,b,c from table1 union all select ca,cb,cc from table2 3.左外连接 与 右外连接 (left

(转)SQL 常用语句

SQL 常用语句积累: 一. SQL 基本语句 SQL 分类: DDL —数据定义语言 (Create , Alter , Drop , DECLARE) DML —数据操纵语言 (Select , Delete , Update , Insert) DCL —数据控制语言 (GRANT , REVOKE , COMMIT , ROLLBACK) 首先 , 简要介绍基础语句: 1 .说明:创建数据库 Create DATABASE database-name 2 .说明:删除数据库 drop d

PL/SQL常用语句

> 2.显示当前连接用户  SQL> show user  3.查看系统拥有哪些用户  SQL> select * from all_users;  4.新建用户并授权  SQL> create user a identified by a;(默认建在SYSTEM表空间下)  SQL> grant connect,resource to a;  5.连接到新用户  SQL> conn a/a  6.查询当前用户下所有对象  SQL> select * from t