Navicat工具安装及单表查询

安装:一路下一步即可
使用:
连接:
 连接名称:自定义
 主机名称或IP地址:默认为localhost
 端口:默认3306
 用户名:默认root
 密码:123456
双击创建的连接-->变成绿色,说明连接成功
创建库:
 点击连接名称-->右键-->新建数据库-->库名:自定义,字符集:utf8,排序规则:utf8-unicode-ci
创建表:
 表-->右键-->新建表-->添加字段名:类型、长度、约束,金钥匙表示主键,allow null->打钩表示允许为空,add field ->在下方增加字段,insert field ->在上方增加字段,delete field->删除字段
向表中插入数据/记录
 双击表-->在字段下添加记录
 √:保存/更新
 +:增加记录
 -:删除记录
 refresh:刷新
建表语句:
 格式:create table 表名(字段名 类型(长度) 约束,字段名 类型(长度) 约束,.... )
  例:create table xyb(xm varchar(20) not null,nl int not null,xb enum('男','女'),jg char(50) not null)
多个字段组成主键:
 在语句的末尾加上:primary key(字段1,字段2...)
自增字段作为主键:
 create table 表名(id int primary key auto_increment,字段名 类型 约束....)
注释:
 单行注释:-- 、 #
 多行注释:/*内容*/


单表查询:
 精确查询:
相等:=
不相等:!=、<>
   例:select * from xyb where xm='XXX'
          select * from xyb where xm!='XXX'/xm<>'XXX'
 模糊查询:like/ not like
  %:匹配多个字符
 _:匹配单个字符,且必须有单个字符
 例:select xm from xyb where xm like '%X%'/xm like 'X_'
 比较查询:>,<,>=,<=
 例:select nl from xyb where nl>18/ nl<18/ nl<=18/ nl>=18
 逻辑运算:and/or
  and优先级高于or
   例:select xm from xyb where jg='上海' or jg='北京'
            select xm from xyb where xm='XXX' and jg='上海'
 区间运算:between...and
   例:select * from xyb where nl between 18 and 20
 集合运算:in/not in
   例:select xm from xyb where jg in('北京','上海')
     select xm from xyb where jg ont in('上海','北京')
 非空运算:is null/is not null
 例:select xm from xyb where xm is null
       select xm from xyb where xm is not null
 排序:order by 字段名
desc:降序
asc:升序,默认为升序
 例:select nl from xyb where nl order by nl desc
 例:select nl from xyb where nl order by nl asc
 去重关键字:distinct 字段名
 例:select distinct jg from xyb 
 聚合函数:
max(字段名):最大值
min(字段名):最小值
avg(字段名):平均值
sum(字段名):总数/和
count(*):表中有多少条数据/记录
   例:select max(nl),min(nl),avg(nl),sum(nl) from xyb
     select count(*) from xyb
 分组:group by 字段名,分组后条件用having
  例:select count(*) from xyb group by xb
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值