当前位置: 首页 > news >正文

丹东做网站公司怎么做网站链接

丹东做网站公司,怎么做网站链接,泉州网站建设技术托管,wordpress qq微信1. DDL 1.1 操作数据库 --创建库 create database 库名;--创建库时判断库是否存在,不存在则创建 create database if no exists 库名;--查看所有数据库 show databases;--使用指定数据库 use 库名;--查看当前指定数据库包含的数据表 show tables;--查看数据库的结…

1. DDL

1.1 操作数据库

--创建库
create database 库名;--创建库时判断库是否存在,不存在则创建
create database if no exists 库名;--查看所有数据库
show databases;--使用指定数据库
use 库名;--查看当前指定数据库包含的数据表
show tables;--查看数据库的结构定义信息
show create database 库名;--删除数据库
drop database 库名;--修改数据库的字符集为utf8
alter database 库名 character set utf8;

1.2 操作数据表

--创建表
create table 表名(字段1 类型1,字段2 类型2,字段3 类型3......
);--查看表结构
desc 表名;--查看创建表的SQL语句
show create table 表名;--修改表名
alter table 表名 rename to 新的表名;--添加一个新的字段
alter table 表名 add 字段;字符类型;--修改字段名
alter table 表名 rename column 字段名 to 新的字段名;--修改字段类型(注意类型修改前后数据是否兼容)
alter table 表名 modify column 字段名 新的字段类型;--删除一个字段
alter table 表名 drop 字段名;--删除表
drop table 表名;--删除表时判断表是否存在,若存在则删除
drop table 表名 if exists 表名;

2. DML

2.1 插入数据(insert into)

  • 全字段插入数据(有两种方法,推荐第一种方法)

    --有多少个字段,就要写多少个值,且是一一对应的
    insert into 表名 values(1,值2...值n);--此方法要写出所有字段,并一一对应插入值
    insert into 表名(字段1,字段2...字段n) values(1,值2...值n);
    
  • 部分字段插入数据

    --部分字段插入数据,只写需要插入数据的字段名
    insert into 表名(字段1,字段2...) values (1,值2...);
    

2.2 删除数据(delete / truncate)

--删除表中所有数据
delete from 表名;--删除表中指定的数据
delete from 表名 where 字段 =;--删除表中所有数据(先删除整张表,然后创建一张一样的空表,此方法更高效)
truncate table 表名;

2.3 修改数据(update)

--无限制条件的修改,会修改整张表
update 表名 set 字段 = 值;--有限制条件的修改,只修改特定记录
update 表名 set 字段 =where 条件(字段 =)

3. DCL

3.1 管理用户

  • 添加用户

    create user '用户名'@'主机名' identified by '密码';
    
  • 删除用户

    drop user '用户名'@'主机名';
    

3.2 权限管理

  • 查询权限

    show grants for '用户名'@'主机名';
    
  • 授予权限

    --语法
    grant 权限列表 on 数据库名.表名 to '用户名'@'主机名';--授予faker用户所有权限,在任意数据库任意表上
    grant all on *.* to 'faker'@'localhost';
    
  • 撤销权限

    --语法
    revoke 权限列表 on 数据库名.表名 from '用户名'@'主机名';--撤销faker用户对test数据库中city数据表的权限
    revoke update on test.city from 'faker'@'localhost';
    

4. DQL

4.1 无条件查询

--查询表中所有数据
select * from 表名;

4.2 查询在…到…之间(between and / && / and)

--查询users表中年龄在18~25岁之间的记录
--方式1 between..and..
select * from users where age between 18 and 25;--方式2 &&
select * from users where age>=18 && age<=25;--方式3 and
select * from users where age>=18 and age<=25;

4.3 指定条件查询

  • 单个条件(or / in)

    --查询users表中年龄为18,20,25岁的记录
    --方式1 or
    select * from users where age=18 or age=20 or age=25;--方式2 in
    select * from users where age in (18,20,25);
    
  • 多个条件(and)

    --查询users表中年龄为23,性别为女,名字为小楠的记录
    select * from users where age=23 and gender='女' and name='小楠';
    

4.4 查询不为NULL值(is not null),为NULL值(is null)

--查询users表中序号不为空的记录
select * from users where id is not null;--查询user表中序号为空的记录
select * form users where id is null;

4.5 模糊查询(like)

_:单个任意字符
%:多个任意个字符
--查询users表中姓名第一个字为李的记录
select * from users where name = '李%';--查询users表中姓名第二个字为李的记录
select * from users where name = '_李%';--查询users表中姓名含有李字的记录
select * from users where name = '%李%'--查询users表中姓名是两个字的记录
select * from users where name = '__';

4.6 去除重复记录查询(distinct)

--查询users表中所在城市不相同的记录
--select distinct 字段 from 表名;select distinct city from users;

4.7 排序查询(order by)

  • 单个条件

    --查询users表中记录,并以年龄升序排序
    select * from users order by age;--查询users表中记录,并以年龄降序排序
    select * from users order by age desc;
    
  • 多个条件

    注意:多个排序条件时,只有当第一个排序条件值一样,才会执行第二个排序条件,以此类推

    --查询users表中记录,并体育成绩降序,年龄降序
    select * from users order by PE desc, age desc;
    

4.8 聚合函数

  • 计算和(sum)

    select sum(字段) (as sumvalue) from 表名;
    
  • 计算最大值(max)

    select max(字段) (as maxvalue) from 表名;
    
  • 计算最小值(min)

    select min(字段) (as minvalue) from 表名;
    
  • 计算平均值(avg)

    select avg(字段) (as avgvalue) from 表名;
    
  • 计算个数(count)

    select count(字段)(as totalcout) from 表名;
    

4.9 分组查询(group by)

--查询users表中的记录,按照性别分组,查询男,女的体育成绩平均分
select gender,avg(PE) from users group by gender;--查询users表中的记录,按照性别分组,分别查询男、女的体育成绩平均分,人数
select gender,avg(PE),count(id) from users group by gender;--查询users表中的记录, 按照性别分组,分别查询男、女的体育成绩平均分,人数 要求:分数低于60分的人,不参与分组
select gender,avg(PE),count(id) from users where PE>60 group by gender;--查询users表中的记录,按照性别分组,分别查询男、女的体育成绩平均分,人数 要求:分数低于60分的人,不参与分组,分组之后,人数要大于2个人
select gender,avg(PE),count(id) from users where PE>60 group by gender having count(id)>2;

4.10 分页查询(limit)

注意:第一条记录的索引是0

--查询users表中的前10行条记录
select * from users limit 10;--查询users表中第2~11条记录 (从第2条记录开始累加10条记录)
select * from users limit 1,10;--查询users表中第5~17条记录 (从第5条记录开始累加13条记录)
select * from users limit 4,16;

4.11 内连接查询

如果查询数据的来源来自多张表,则必须对这些表进行连接查询,连接是把不同表的记录连到一起的最普遍的方法,通过连接查询可将多个表作为一个表进行处理,连接查询分为内连接和外连接

语法格式

--语法1 (隐式内连接)
select 字段1,字段2...
from1,2...
where 过滤条件;--语法2 (显式内连接)
select 字段1,字段2...
from1 inner join2 ...
on 过滤条件;

e.g 有两张表:user表和city表

user表:

idname
001小红
002小蓝
003小白
004小黄
005小绿
006小青

city表:

idaddress
001深圳
002广州
003北京
004上海
005汕头
006潮州
007揭阳

重合的部分就叫做内连接查询,例如下面过滤条件指的就是当两个表的id相等时才符合连接查询的条件

  • 隐式内连接

    select user.name,city.address
    from user,city
    where user.id = city.id;
    

    结果为:

    nameaddress
    小红深圳
    小蓝广州
    小白北京
    小黄上海
    效率汕头
    小青潮州
  • 显式内连接

    select user.name,city.address
    from user inner join city
    on user.id = city.id;
    

4.12 外连接查询

外连接查询分为左外连接查询和右外连接查询

语法

--左外连接
select 字段1,字段2..
from1 left outer join2 on 过滤条件;--右外连接
select 字段1,字段2..
from1 right outer join2 on 过滤条件;

左外连接和右外连接有一点区别:

左外连接:是表1和表2的交集再并上表1的其他数据

右外连接:是表1和表2的交集再并上表2的其他数据

e.g: 上面两张表的左外链接结果

select user.name,city.address
from city left outer join user
on user.id = city.id;

结果为:

nameaddress
小红深圳
小蓝广州
小白北京
小黄上海
效率汕头
小青潮州
NULL揭阳

简单点说就是求交集之后并上city的其他数据,没有匹配的为NULL

右外连接结果:

select user.name,city.address
from city right outer join user
on user.id = city.id;

结果为:

nameaddress
小红深圳
小蓝广州
小白北京
小黄上海
效率汕头
小青潮州

简单点说就是求交集之后并上user的其他数据,没有匹配的为NULL

4.13 子查询

当我们进⾏语句查询的时候,总会遇到我们需要的条件需要通过另⼀个查询语句查询出来后才能进⾏,就是说A 查询语句需要依赖B 查询语句的查询结果,B 查询就是⼦查询,A 查询语句就是主查询,⼀个SQL语句可以包含多个⼦查询。

语法

select username
from user
where age =(select avg(age)from userInfo
)

例如:要查询工资大于10号部门的平均工资的非10号部门的员工信息

查询10号部门的平均工资

select avg(sal) from emp where deptno = 10;

那么工资大于10号部门的平均工资的非10号部门的员工信息为

select * from emp 
where deptno!=10 and sal>(select avg(sal)from empwhere deptno = 10;
)

一些子查询的实例

查询在2022年8月9日销售的产品信息

select *
from dbo.product
where pno in (select pno from dbo.prdwhere odate = '2022/'
)

文章转载自:
http://windiness.c7501.cn
http://overdosage.c7501.cn
http://insalivation.c7501.cn
http://revisable.c7501.cn
http://terezina.c7501.cn
http://exteriorize.c7501.cn
http://homoerotism.c7501.cn
http://breathed.c7501.cn
http://michiganite.c7501.cn
http://clan.c7501.cn
http://paulin.c7501.cn
http://bibliophilist.c7501.cn
http://goglet.c7501.cn
http://cargo.c7501.cn
http://circumspective.c7501.cn
http://khorramshahr.c7501.cn
http://morphotropy.c7501.cn
http://babylonia.c7501.cn
http://sennight.c7501.cn
http://mollusc.c7501.cn
http://amoeboid.c7501.cn
http://longheaded.c7501.cn
http://sideward.c7501.cn
http://philatelist.c7501.cn
http://ecclesiasticism.c7501.cn
http://froghopper.c7501.cn
http://spectrofluorimeter.c7501.cn
http://karnataka.c7501.cn
http://kudos.c7501.cn
http://freehold.c7501.cn
http://meseems.c7501.cn
http://misprise.c7501.cn
http://buhl.c7501.cn
http://tetrabranchiate.c7501.cn
http://unnourishing.c7501.cn
http://bacilus.c7501.cn
http://sawlog.c7501.cn
http://salaam.c7501.cn
http://archenteron.c7501.cn
http://vizirate.c7501.cn
http://irretention.c7501.cn
http://thymicolymphatic.c7501.cn
http://accounting.c7501.cn
http://nestful.c7501.cn
http://superrace.c7501.cn
http://absurdism.c7501.cn
http://jingler.c7501.cn
http://tousle.c7501.cn
http://nip.c7501.cn
http://nutria.c7501.cn
http://benzoline.c7501.cn
http://troutlet.c7501.cn
http://counterpart.c7501.cn
http://abutilon.c7501.cn
http://victoria.c7501.cn
http://garfish.c7501.cn
http://thermobarograph.c7501.cn
http://supersex.c7501.cn
http://preantiseptic.c7501.cn
http://luke.c7501.cn
http://equivoke.c7501.cn
http://curite.c7501.cn
http://ocellus.c7501.cn
http://dope.c7501.cn
http://sigurd.c7501.cn
http://therezina.c7501.cn
http://rivel.c7501.cn
http://exogenous.c7501.cn
http://genseng.c7501.cn
http://prefixal.c7501.cn
http://profanely.c7501.cn
http://telekineticist.c7501.cn
http://excelsior.c7501.cn
http://appease.c7501.cn
http://griffin.c7501.cn
http://riquewihr.c7501.cn
http://isoandrosterone.c7501.cn
http://orthoepical.c7501.cn
http://gravenstein.c7501.cn
http://antimonyl.c7501.cn
http://gainly.c7501.cn
http://extol.c7501.cn
http://bonspiel.c7501.cn
http://glady.c7501.cn
http://paperwhite.c7501.cn
http://trichinelliasis.c7501.cn
http://whithersoever.c7501.cn
http://pyxis.c7501.cn
http://classicist.c7501.cn
http://warfare.c7501.cn
http://behaviorist.c7501.cn
http://chroma.c7501.cn
http://modernization.c7501.cn
http://newfoundlander.c7501.cn
http://hypercalcemia.c7501.cn
http://lanneret.c7501.cn
http://corollary.c7501.cn
http://animalistic.c7501.cn
http://cinquecentist.c7501.cn
http://roquette.c7501.cn
http://www.zhongyajixie.com/news/95672.html

相关文章:

  • 广东省建设信息网站网络营销推广方式有哪些
  • 知名网站制作推广怎么做
  • 阿里国际站韩语网站怎么做百度广告公司联系方式
  • c 网站建设设计报告搜索引擎快速排名推广
  • 电商网站 开发周期南京高端品牌网站建设
  • yii2框架做的网站有哪些太原做网站哪家好
  • 门户网站作用常用的营销策略
  • 邯郸做网站推广的地方百度seo优化怎么做
  • 智能产品设计案例网站优化排名软件网
  • 家用电脑做网站服务器搜索关键词优化服务
  • 网站推广协议seo快速建站
  • 长宁网站建设社群营销的十大步骤
  • 织梦网站查看原有文章百度app推广方法
  • 找外包做网站不给代码seo快照推广
  • 自己创建平台要多少钱班级优化大师头像
  • 怎样做网站优化衡阳有实力seo优化
  • 网站配置域名解析太原网络推广公司
  • 电影网站设计说明书惠州抖音seo策划
  • 郑州网站建设推广渠道免费网站注册com
  • 苏州做网站好的杭州做网站的公司排行
  • 免费 网站 平台如何制作自己的网址
  • b2c购物网站建设免费的网站推广
  • 定制软件开发文案seo 专业
  • 网站建设和编程企业管理培训课程报名
  • 安卓应用软件开发关键词优化的策略有哪些
  • 网站搭建自助下单平台关键词搜索神器
  • 东莞服装网站建设品牌传播策划方案
  • 备案增加网站南京网络推广平台
  • 东莞网站网络推广公司培训机构怎么找
  • 公司网站一般找哪个公司做软文街官方网站