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

重庆网站建设外包哪家好百度网盟推广

重庆网站建设外包哪家好,百度网盟推广,网站建设运营维护方案,二字简单大气公司名字目录 1. 常用数据类型 2. 约束 3. 数据库操作 4. 数据表操作 查看表 创建表格 添加数据 删除数据 修改数据 单表查询数据 多表查询数据 模糊查询 关联查询 连接查询 数据查询的执行顺序 4. 内置函数 1. 常用数据类型 整型:int浮点型:flo…

目录

1. 常用数据类型

2. 约束

3. 数据库操作

4. 数据表操作

查看表

创建表格

添加数据

删除数据

修改数据

单表查询数据

多表查询数据

模糊查询

关联查询

连接查询

数据查询的执行顺序

4. 内置函数


1. 常用数据类型

  • 整型:int
  • 浮点型:float
  • 字符型:varchar
  • 年月日:data
  • 年月日 时分秒:datatime

2. 约束

  • primary key:主键,物理上的存储顺序,主键一定是非空、唯一的
  • not null:此字段不允许为空
  • unique:此字段不允许重复
  • default:默认,当此字段无数据时,会填入默认值
  • foreign key:对关系数据进行约束,当为关键字填写值时,会到关联的表中查询此值是否存在,如果存在则填写成功,如果不存在则填写失败并抛出异常

3. 数据库操作

--查看数据库
show databases;--创建数据库
create database database_name;--删除数据库
drop database database_name;--选择数据库
use database_name;--查看当前数据库
select database();

4. 数据表操作

查看表

--查看当前数据库中的所有表
show tables;--查看表结构
desc table_name;

创建表格

--创建表格示例
create table if not exists `test_table`(`id` int unsigned auto_increment comment '编号',`title` varchar(100) not null comment '标题', `author` varchar(100) not null comment '作者', `cdate` date comment '日期', primary key (`id`)
)engine=InnoDB default charset=utf8 comment='测试表格';--if not exists `test_table`:如果 test_table 这张表不存在则新建
--auto_increment:从上一条数据自增 1 
--comment:后面的字符串为注释
--not null:如果该字段无数据则默认为 null

添加数据

--新增字段示例
alter table test_table add `position` varchar(100) not null comment '地区';--写入数据
insert into test_table(title,author,position,cdate
)value('孔乙己', '鲁迅', '中国', '1919-4-1');--批量写入
insert into test_table(title,author,position,cdate
)value('药', '鲁迅', '中国', '1919-4-25'),('白夜行', '东野圭吾', '日本', '1998-8-1'),('鲁宾逊漂流记', '笛福', '英国', '1719-4-25');

删除数据

--删除表
drop table table_name;--删除字段
alter table table_name drop column `字段名`;--删除数据
drop from table_name where 条件;

修改数据

--修改字段名示例
alter table test_table change `title` `book` varchar(100) not null comment '作品';--更新数据示例
update test_table
setbook = '彷徨',cdate = '1926-8-1'
where id = 1;

单表查询数据

--查询所有数据
select * from test_table;--限制数量查询
select * from test_table
limit 3;--查找指定字段数据
selectbook,author
from test_table;

 

多表查询数据

--多表查询示例
--新建另一个测试表格test_01
--test_01的字段是 id title author cdate
--test_01存储影视信息
selecttest_table.book,test_table.author,test_01.title,test_01.author
from test_table, test_01;--条件查询
select *
from table1, table2, ...
where 条件;select *
from table1, table2, ...
where 条件1         --选定表格后,选择数据前继续筛选
having 条件2;       --数据全部计算完之后进行筛选--起别名示例
selecta.id,a.book,a.author
from test_table a;--按字段数据去重查询示例
select distincta.author
from test_table as a;

模糊查询

--模糊查询1示例
select *
from test_table
where author like '%鲁%';   -- % 可匹配任意字符,一个或多个,也可不匹配--模糊查询2示例
select *
from test_table
where cdate between '1900-1-1' and '2000-1-1';--模糊查询3示例
select *
from test_table
where author in ('鲁迅', '陈独秀', '李大钊');

关联查询

--关联:将两张表拼接
--两张表的字段名可以不不相同,但字段数量字段类型要相同
--union distinct
selectid,book,author
from test_table
union
select id,title ,author
from test_01;--排序
--默认是从小排到大,加上desc是从大到小
--每个字段后面的参数只代表这个字段的排序法则
select * 
from test_table
order by cdate desc, id;    --优先排序出版时间逆序,再根据编号正序排序--聚合
--count(0)  统计数据条数
--min  max  avg  分别用于找最大值、最小值、平均数
selectcount(0)        ,min(cdate),max(cdate),avg(cdate)
from test_table;--分组
select book,author,count(0)
from test_table
group by book, author;
--用 group by 去重比 distinct 效率高--分组统计
selectcoalesce(字段1, 'total'),coalesce(字段2, 'total')
from 表名
where 条件
group by 字段1, 字段2
with rollup;

连接查询

        连接查询
        可同时关联两张表或多张表

        内连接
        join默认为内连接 inner join
        内连接:保留两个关联表的交集

selecta.*,b.*
from test_table as a
join test_01 as bon a.id = b.idand a.author = '鲁迅';

 

        左连接 

        左连接 left join
        保留主表的全部数据和关联表的交集数据

selecta.*,b.*
from test_table as a
left join test_01 as bon a.id = b.id;

 

        右连接
        右连接 right join
        通过调换字段顺序可以将右连接改为左连接

selecta.*,b.*
from test_01 as a
right join test_table as bon a.id = b.id;

 

        自关联

create table if not exists `city` (`id` int not null comment '编号',`name` varchar(100) comment '城市名称',`pid` varchar(4) comment '父id',primary key (`id`)
)engine=InnoDB default charset=utf8 comment='城市表格';insert into city(id,name,pid) values 
(1,'上海市',null),
(12,'闵行区',1),
(13,'浦东新区',1),
(2,'北京市',null),
(23,'朝阳区',2),
(24,'海淀区',2),
(25,'望京区',2),
(3,'广东省',null),
(31,'广州市',3),
(32,'东莞市',3),
(33,'珠海市',3),
(321,'莞城区',32);selecta.ID,a.name,b.ID,b.name,c.ID,c.name
from city a
left join city bon a.ID = b.PID
left join city con b.ID = c.PID
where a.PID is null;

 

数据查询的执行顺序

--代码格式
select distinct字段
from 表名
join
where
group by
having 
order by
limit start, count--执行顺序
from 表名
join
where
group by
select distinct 字段
having
order by
limit start, count

4. 内置函数

        常用默认函数

--当前日期
now()
--年
year(now())
--月
month(now())
--日
day(now())--字段长度
length(字段) from table_name;--设置返回值最小位数
select round(字段, 小数位数) from table_name;--反转字符串
select reverse(字符串);--截取字符串
select substring(字符串, start, length);--判空  ifnull/nvl/coalesce
--如果对象为空,则用默认值代替
select ifnull(对象, 默认值)

        

        条件判断

--条件判断
select
case when 条件1 then ...when 条件2 then ...else ...end 新增字段
from table_name;--示例
selecttest_table.*,case when author = '鲁迅' then '鲁迅文集'when position = '日本' then '日本文学'else '西方文学'end '文化特色'
from test_table;

        开窗函数

--开窗函数  partition by
--function(column) over(partition by 字段1, 字段2...) 新增字段
--function通常为聚合、排序函数--分类统计不同作者、不同国家的人
select *,count(id) over(partition by author, position) num
from test_table;--排序函数
--row_number()  排序名次累加,并列也累加                1 2 3 4 5 6 ...
--rank()        排序名次可并列,遇到并列则跳过该名次     1 2 2 4 4 6 ...
--dense_rank()  排序名次可并列,遇到并列不跳过名次       1 2 2 3 3 4 ...
select row_number() over(order by 字段) 新增字段;
select rank() over(order by 字段) 新增字段;
select dense_rank() over(order by 字段) 新增字段;--查询写入
insert into select ......
--将查询到数据写入另一个表格中,要求写入的数据一一对应

 

 


文章转载自:
http://gainer.rnds.cn
http://sugarworks.rnds.cn
http://inspective.rnds.cn
http://endothermal.rnds.cn
http://counterscarp.rnds.cn
http://acoustic.rnds.cn
http://benedictional.rnds.cn
http://airometer.rnds.cn
http://coloured.rnds.cn
http://semiprivate.rnds.cn
http://theoretic.rnds.cn
http://kinabalu.rnds.cn
http://palely.rnds.cn
http://salvage.rnds.cn
http://chaffing.rnds.cn
http://tickler.rnds.cn
http://sudd.rnds.cn
http://bored.rnds.cn
http://ontological.rnds.cn
http://misinformant.rnds.cn
http://agname.rnds.cn
http://oneirocritical.rnds.cn
http://tapotement.rnds.cn
http://litter.rnds.cn
http://hemodialyzer.rnds.cn
http://nictate.rnds.cn
http://polemize.rnds.cn
http://crimea.rnds.cn
http://ecsc.rnds.cn
http://megalocardia.rnds.cn
http://vad.rnds.cn
http://northumbria.rnds.cn
http://acrobatic.rnds.cn
http://turbofan.rnds.cn
http://practiced.rnds.cn
http://geodesic.rnds.cn
http://organelle.rnds.cn
http://paralipsis.rnds.cn
http://overglaze.rnds.cn
http://canzona.rnds.cn
http://nobbily.rnds.cn
http://decoy.rnds.cn
http://cowgrass.rnds.cn
http://illiberal.rnds.cn
http://insist.rnds.cn
http://hexadecimal.rnds.cn
http://cypress.rnds.cn
http://feneration.rnds.cn
http://erythromycin.rnds.cn
http://joseph.rnds.cn
http://willemstad.rnds.cn
http://bouffe.rnds.cn
http://flaccid.rnds.cn
http://directorate.rnds.cn
http://brenner.rnds.cn
http://jubal.rnds.cn
http://rabbinist.rnds.cn
http://releasee.rnds.cn
http://impolder.rnds.cn
http://creatress.rnds.cn
http://invigorate.rnds.cn
http://wetness.rnds.cn
http://unicursal.rnds.cn
http://cowichan.rnds.cn
http://correlated.rnds.cn
http://potomac.rnds.cn
http://luzon.rnds.cn
http://rhomboid.rnds.cn
http://syllabize.rnds.cn
http://buzz.rnds.cn
http://scatheless.rnds.cn
http://yabby.rnds.cn
http://lucre.rnds.cn
http://aplenty.rnds.cn
http://kickapoo.rnds.cn
http://turnstile.rnds.cn
http://adless.rnds.cn
http://liturgics.rnds.cn
http://boysenberry.rnds.cn
http://butterfly.rnds.cn
http://wigged.rnds.cn
http://vortumnus.rnds.cn
http://madras.rnds.cn
http://rereward.rnds.cn
http://asbestoid.rnds.cn
http://brayton.rnds.cn
http://amicron.rnds.cn
http://creche.rnds.cn
http://sone.rnds.cn
http://cleansing.rnds.cn
http://menopausic.rnds.cn
http://trihedron.rnds.cn
http://geological.rnds.cn
http://heriot.rnds.cn
http://oxyparaffin.rnds.cn
http://hereunto.rnds.cn
http://antiviral.rnds.cn
http://anglophile.rnds.cn
http://ethylate.rnds.cn
http://psephology.rnds.cn
http://www.hrbkazy.com/news/85862.html

相关文章:

  • 深圳有没有可以做家教的网站网站之家查询
  • 数字创意设计包括哪些行业seo技术自学
  • dede企业网站模板华与华营销策划公司
  • 广州网站推广公司厦门网站seo哪家好
  • 上海做宴会的网站站长工具友链查询
  • 企业网站建设可以分为哪些层次如何做好线上营销
  • 石材外贸网站搜索引擎营销sem
  • 微信支付 网站建设百度推广投诉热线
  • 哪些网站做的比较好看的外贸独立站建站
  • wordpress设置html代码深圳谷歌seo推广
  • 聊城做网站的公司案例太原seo排名公司
  • 坪山网站建设哪家便宜乔拓云智能建站
  • 做网站视频博彩如何设计网站步骤
  • 鲅鱼圈网站开发哪家好哦爱站网关键词工具
  • 网站如何做vip等级竞价推广托管开户
  • 具有品牌的上海网站建设怎么开发一个网站
  • 郑州做网站公司排关键词网站排名查询
  • 做美食原创视频网站广州信息流推广公司
  • 商城网站建设公司怎么制作seo搜索优化
  • 唐山免费网站制作临沂seo建站
  • 新网站怎么做谷歌推广呢谷歌推广seo
  • 玉环做网站天津百度快速排名优化
  • 柯桥区建设集团网站线上营销策划方案
  • 养生网站源码下载个人网页制作成品
  • seo诊断晨阳seo 优化思路
  • 重庆城乡建设委员会的网站搜索引擎实训心得体会
  • 做时时彩网站需要加盟郑州网络推广效果
  • 什么网站百度收录好北京本地网络推广平台
  • 湛江搜索引擎网站推广广告网络推广
  • 美国做短视频网站网站关键词挖掘