位置: 编程技术 - 正文

最全的mysql查询语句整理(mysql查询语句菜鸟教程)

编辑:rootadmin

推荐整理分享最全的mysql查询语句整理(mysql查询语句菜鸟教程),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:mysqljoin查询,mysql在线查询,mysql查询技巧,mysql查询语句菜鸟教程,mysql查询技巧,mysql数据查询,mysql在线查询,mysql查询技巧,内容如对您有帮助,希望把文章链接给更多的朋友!

-- 基本查询

select * from pet

-- 列出指定的列

select name, owner form pet

-- 直接进行算术运算,对字段起别名

select sin(1+2) as sin

--where 条件

select * from pet where (birth>'' and species='dog') or species='bird'

-- 对null 的条件

select * from pet where sex is not null

-- 所有名字第四位是n 的宠物信息是

select * from pet where owner like '___n%'

-- 所有主人名叫gwen 或benny 的宠物

select * from pet where owner in ('gwen' , 'benny')

-- 查询出生日期在 年代是宠物,相当与 >= and <=

select * from pet where birth between '' and ''

-- 按主人姓名排序,相同的按宠物姓名倒序排列

select * from pet order by owner, name desc

-- 查询性别为公的宠物,按生日倒序排列

select * from pet where sex='m' order by birth desc

--char_lenngth() 返回的字符的长度,length() 返回字节长度

SELECT owner,length(owner),char_length(owner) FROM pet p;

-- 列出养有宠物狗的人名

select distinct owner from pet where species='dog'

-- 用两种方法查询出所有狗和猫的名字、出生年份、出生月份

select name, left(birth,4) as year, mid(birth, 6, 2) as month from pet

where species='dog' or species='cat'

select name, year(birth) as year, month(birth) as month from pet

where species in('dog','cat')

-- 查询所有名字中存在字母'e' 的人,将他们养的宠物按类别、年龄排序

select name, species, birth

from pet

where owner like '%e%'

order by species,birth desc

-- 数字函数

select round(2.,2), truncate(2.,2), mod(,5)

-- 日期函数

select now(), curdate(), curtime()

select adddate('--', interval day)

-- 求出所有宠物的年龄

select name,birth,

truncate(datediff(now(),birth)/,0) as age1,

year(now())-year(birth) - (dayofyear(birth)>dayofyear(now())) as age2

from pet

-- 分组函数

select min(birth),max(birth),avg(birth),count(*),count(sex),

sum(birth)

from pet

-- 每种宠物各有几只

select species,count(*)

from pet

group by species

-- 查询年龄最大的宠物的信息

select * from pet where birth =

(select max(birth) from pet)

-- 每年各出生了几只宠物

select year(birth), count(*) from pet group by year(birth)

-- 鸟和猫的性别比例

select species, sex, count(*)

from pet

where species in ('cat','bird')

group by species, sex

-- 各种宠物年龄的和

select species, sum(truncate(datediff(now(),birth)/,0)) as SumAge

from pet

group by species

-- 数量大于1 的宠物种类

select species, count(*) as c

from pet

最全的mysql查询语句整理(mysql查询语句菜鸟教程)

group by species

having c>=2

-- 基本双表关联

select a.name,a.species, a.sex,b.date, b.type, b.remark

from pet a,event b

where a.name = b.name

-- 查询宠物产仔时的年龄

select a.name, a.species,

truncate(datediff(b.date,a.birth)/,0) as age

from pet a,event b

where a.name = b.name and b.type='litter'

-- 年代出生的狗的事件列表

select a.name,birth,species,sex,date,type,remark

from pet a,event b

where a.name=b.name and birth between '' and ''

and species='dog'

-- 活着的宠物按发生的事件类型分组,看各种事件发生的次数

select type, count(*)

from pet a, event b

where a.name=b.name and a.death is null

group by type

-- 记录的事件数量超过1 条的宠物信息

select a.name,species,sex,count(*)

from pet a, event b

where a.name = b.name

group by b.name

having count(*)>=2

-- 列出发生了两件事情的宠物的事件记录信息

select a.name,type,date,remark,b.species,b.sex,b.owner

from event a, pet b

where a.name=b.name and

b.name in

(

select name

from event

group by name

having count(*)=2

)

-- 插入语句

insert into pet (name,species,birth)

values ('KKK','snake','--');

insert into pet

values ('KK','Diane','cat','f',null,null);

insert into pet set name='k',owner='Benny'

-- 更新语句

update pet set species='snake',sex='f',birth=now()

where name='k'

-- 将事件表中生日的日期,更新到pet 表中相应宠物的birth 字段

update pet a

set birth = (

select date

from event b

where a.name=b.name and b.type='birthday'

)

where a.name in (

select name

from event

where type='birthday'

)

-- 删除语句

delete from pet where name like 'k%'

基本查询语句

SELECT * FROM `test` WHERE 1                  //简单查询SELECT id,uid FROM newdb.`test` WHERE 1            //查询ID、UID等字段SELECT remark as r FROM `test` WHERE 1             //别名查询SELECT * FROM `test` WHERE id=1,3               //条件查询,相等SELECT * FROM `test` WHERE id<>2,3               //条件按查,不相等SELECT * FROM `test` WHERE id in (1,2,4)             //in查询,即查询ID为1,2,4的数据SELECT * FROM `test` WHERE not in (2,3)           //in查询,查询ID不是2,3的数据SELECT * FROM `test` WHERE `uid` like '%王%'         //like模糊查询,%*%前后匹配SELECT * FROM `test` WHERE id BETWEEN 1 and 3       //条件查询,中间数据SELECT * FROM `test` WHERE id NOT BETWEEN 1and3      //条件查询SELECT * FROM `test` WHERE id=1 and `remark`='学生'    //多个条件SELECT * FROM `test` group by `remark`        //查询排序SELECT * FROM `test` order by `regdate` ASC //order by升序排序,放到limit之前SELECT * FROM `test` order by `regdate` ASC,id DESC //order by按照注册时间升序,ID降序ASC 升序、DESC降序。

SELECT * FROM `test` limit 0,3 //数据条数限制,输出三条SELECT count(*) FROM `test` WHERE 1 //统计查询,可以查询单个统计,例如count(name)SELECT max(id) FROM `test` WHERE 1 //统计ID最大值是多少以下三个和以上max用法类似MIN(*)最小值函数AVG(*)平均值函数SUM(*)累计值函数

基本插入语句:

insert into test (`id`,`uid`,`regdate`,`remark`) values ('','PHP','--','工人')    //ID自增,insert into test (`id`,`uid`,`regdate`,`remark`) values ('','PHP','now()','工人')insert into test values ('','PHP','now()','工人')                         //简便写法,但不提倡

更新语句:

update test set uid='php' where id=6                             //set 后是要改后的内容。where 后是更改位置

删除语句:

Delete from dbname.`test` where id=3

MySQL查询语句大全集锦 1:使用SHOW语句找出在服务器上当前存在什么数据库:mysqlSHOWDATABASES;2:2、创建一个数据库MYSQLDATAmysqlCREATEDATABASEMYSQLDATA;3:选择你所创建的数据库mysqlUSEMYSQLDA

windows下安装、卸载mysql服务的方法(mysql 5.6 zip解压版安装教程) MySQL是一个小巧玲珑但功能强大的数据库,目前十分流行。但是官网给出的安装包有两种格式,一个是msi格式,一个是zip格式的。很多人下了zip格式的解

MySQL绿色版(zip解压版)的安装图文教程(mysql-5.6.-win.zip) 1、数据库下载Mysql官方网站:

标签: mysql查询语句菜鸟教程

本文链接地址:https://www.jiuchutong.com/biancheng/347561.html 转载请保留说明!

上一篇:Mysql判断表字段或索引是否存在(mysql 判断)

下一篇:MySQL查询语句大全集锦(mysql查询语句大全讲解)

  • 偷税行为五年后被发现要接受行政处罚吗?
  • 跨年的预收账款怎么记账
  • 个人申请代开发票流程怎么操作
  • 应付账款周转率和存货周转率公式
  • 小微企业减免增值税申报表填写
  • 三证合一后税务登记证要收回吗
  • 个体工商户开普票流程
  • 企业除了增值税还有什么税
  • 利润表中利润总额是什么
  • 销售人员的提成属于什么工资
  • 法人购买设备怎么入账
  • 发票报销哪些能用专票
  • 以前年度漏记一笔短期借款但本金利息支出记账了
  • 预收房款发票开具需要注意哪些?
  • 营改增后消防维保税率是多少?
  • 销项税额抵减是怎么回事
  • 增值税的税额是什么意思
  • 因为买房子
  • 小企业报表为什么勾选不到小型微利企业
  • 总账会计需要做账吗
  • 个税按工资薪金未按时申报的处罚规定
  • 临时设施需要验收吗
  • 增值税退税金额怎么算
  • 鸿蒙系统怎么升级3.0
  • 商品售价有规定吗
  • 电脑不能连接wifi只能连宽带
  • mysql 数据源
  • 情人节海报怎么画简单
  • ie浏览器进程
  • 福利部门领用原材料进项税额可以抵扣吗
  • 税款滞纳金会计处理
  • php数组数据结构
  • springmvc执行流程简单
  • 带有折扣的增值税怎么算
  • 抄税清卡是一个意思吗
  • 电子税务局附加税退税在哪看
  • 主营业务成本和生产成本的区别
  • 个人所得税经营所得
  • 购买加油卡如何做会计分录
  • 账上没有实收资本
  • 公司收到个人汇款怎么开发票
  • 营改增后材料价差调整
  • 分红需要满足的条件包括
  • 新会计准则印花税规定
  • 受托加工的成本
  • 企业固定资产可以不提折旧吗
  • 收到加盟费应该怎么做账
  • 主营业务收入增加计入借方还是贷方
  • 特殊销售方式下销售额的确定
  • 因质量问题质保金未能收回怎么处理
  • 价外费用计入哪个科目
  • 医院体检收入计入什么科目
  • 原材料入库单应根据采购订单还是到货数量
  • ゆうちょ银行转账步骤
  • 史上最简单的飞镖
  • 解决五大问题
  • 彻底关闭windows10自动更新工具
  • centos5.4 安装
  • 怎么自己安装windows7
  • windows 10 mobile apk
  • lsm.exe是什么程序
  • w10系统有什么好处
  • linux用
  • windows补丁kb3033929
  • win10系统升级后共享打印机不能用
  • 启用win8 metro启动界面
  • ES6 javascript中class静态方法、属性与实例属性用法示例
  • perl列表去重
  • unity3d入门视频教程
  • js移动到指定位置
  • 在img标签中的alt属性里添加内容可以告诉
  • android studio unity3d
  • Android Build.prop
  • vim命令详解
  • 梦见擦窗户框
  • python中__init__
  • python3.7怎么安装pil
  • python迭代器iterator
  • 车辆购置税完税证明怎么查询
  • 主题党日活动标题副标题格式
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设