当前位置:网站首页>MySQL基本查询和运算符
MySQL基本查询和运算符
2022-07-27 18:08:00 【小唐同学(๑><๑)】
作者简介:大家好我是小唐同学(๑><๑),大家可以叫我小唐
个人主页:小唐同学(๑><๑)的博客主页
系列专栏:数据库
博友们如果也是新手入门MySQL 我希望大家可以多加练习 MySQL题库在牛客网就有已经给大家附上链接,可以直接点击跳转:点击跳转
牛客网支持ACM模式哦,刷算法题也很推荐哦!!!
下面上文章------》
目录
MySQL基本查询
查询概念:
查询是数据库管理系统中一个重要功能,数据查询不应只是简单返回数据库中存储的信息
还应该根据需要对数据进行筛选以及确定数据以什么形式显示
1.查询所有商品:
select * from 表名;
2.查询某列:
select 列名1,列名2 from 表名;
3.别名查询:
select * from 表名 as 别名;
4.列别名查询:
select 列名1 as 别名,列名2 as 别名 ,from 表名;
5.去重复值查询:
当所有列均相同时才会去重复值(一般不会出现---主键)
select distinct 列名 from 表名;
6.查询结果是表达式--运算查询
select 列名 ,列名+10 别名 from 表名;
用到了别名 运算结果是+10后显示别名 不会修改原表数据;
运算符
运算符概念:数据库中的表结构确定后,表中数据代表的意义就已经确定,通过mysql运算符进行运算就可以获取到表结构以外的另一种数据。
下边以实例演示运算符的应用
1.将所以商品价格上调10%:
select pname ,price*1.1 as new_price from 表名;
2.查询商品名为“海尔洗衣机”的商品的信息
select *from 表名 where pname='海尔洗衣机';
(1)select *from 表名 where price between 100 and 200;
(2) select *from 表名 where price >=100 and price<=200;
3.查询价格是200或800的所以商品:
select *from 表名where price in(200,800);
in 关键字括号中的值满足一个就好
4.like-----通配符匹配
(1)查询含有’裤‘字的所以商品:
select * from 表名 where pname like ’%裤%‘;
(2)查询以’海‘字开头的所以商品:
select * from 表名 where pname like ’海%‘;
(3)查询第二个字为’寇‘的所有商品:
select * from 表名 where pname like ’-寇%‘;
5.NULL的使用:
NULL 不能用= 因为NULL不等于任何值(包括它自己)
查询id不为NULL 的商品
select * from 表名 where列名 is not NULL;
6.函数的使用:
(1)least求最小值:
select least(5,10,20);
select least(5,10,20)as smallnumber;
select least(5,null20);
如果数值中有NULL 则不会进行比较 直接输出NULL
(2)greatest求最大值
select greatest (10,30,20)as bignumber;
select greatest (10,null,20)as bignumber;
如果数值中有NULL 则不会进行比较 直接输出NULL
边栏推荐
- Lennix Lai, OKx financial market director: Web3 is a revolution
- 【数据集显示标注】VOC文件结构+数据集标注可视化+代码实现
- Nailing development document
- Redis Hash 结构命令
- leetcode:1498. 满足条件的子序列数目【排序 + 二分 + 幂次哈希表】
- Introduction to JVs Foundation
- Innovative cases | the growth strategy of digitalization of local life services and upgrading of Gaode brand
- Software test interview question: if a string is known as "hello_world_yoyo", how to get a queue ["hello", "world", "yoyo"]
- 【效率】弃用 Notepad++,这款开源替代品更牛逼!
- How to solve the problem of missing alarm information and synchronization when Haikang equipment is connected to easycvr?
猜你喜欢

【深度学习】视频分类技术整理

做测试, 就得去大厂,内部披露BAT大厂招聘“潜规则”

leetcode:1498. 满足条件的子序列数目【排序 + 二分 + 幂次哈希表】

My approval of OA project (Query & meeting signature)

【阿里安全 × ICDM 2022】20万奖金池!大规模电商图上的风险商品检测赛火热报名中!...

学术分享 | 清华大学 康重庆:电力系统碳计量技术与应用(Matlab代码实现)

【深度学习】Pytorch Tensor 张量

How bad can a programmer be?

人家这才叫软件测试工程师,你那只是混口饭吃(附HR面试宝典)

A new UI testing method: visual perception test
随机推荐
【数据集显示标注】VOC文件结构+数据集标注可视化+代码实现
软件测试面试题:统计在一个队列中的数字,有多少个正数,多少个负数,如[1, 3, 5, 7, 0, -1, -9, -4, -5, 8]
Users and permissions create ordinary users
How to solve the problem of missing alarm information and synchronization when Haikang equipment is connected to easycvr?
MySQL 日志查询日志
Common methods of object learning [clone and equals]
用户和权限撤销用户权限
Anfulai embedded weekly report no. 275: 2022.07.18--2022.07.24
如何监控NVIDIA Jetson的的运行状态和使用情况
How to optimize the open source community experience through developer metrics
When adding RTSP devices to easycvr platform, what is the reason for the phenomenon that they are all connected by TCP?
Session attack
I'm also drunk. Eureka delayed registration and this pit
用户和权限限制用户使用资源
从0开始写bootloader
Get wechat product details API
软件测试面试题:已知一个字符串为“hello_world_yoyo”, 如何得到一个队列 [“hello“,“world“,“yoyo“]
antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key
【效率】弃用 Notepad++,这款开源替代品更牛逼!
【深度学习】Pytorch Tensor 张量