当前位置:网站首页>【mysql学习】8
【mysql学习】8
2022-07-27 05:12:00 【m0_67595943】
insert into cellphone values(null,‘vivo手机’,3600,0.88);
insert into cellphone values(null,‘华为手机’,5500,0.92);
insert into cellphone values(null,‘魅族手机’,3400,0.95);
insert into cellphone values(null,‘菠萝手机’,8000,0.90);
成功创建表后输入select * from cellphone;查看数据是否插入成功,如果显示如下,那么我们的准备工作就完成了。

使用别名
====
我们在进行数据查询时,查询出来的列名往往语义性不是很强,例如,上面我们的显示手机的列名是name,就是名字,是什么名字呢?这就不清楚了。
as的用法就是 旧列名 as 新列名
现在,我们使用as来定义别名,把name换成手机名称。
select name as ‘手机名称’, price, discount from cellphone;

我们使用as后语义性就强很多了。
多个列执行计算
========
我们观察这张表就会发现,手机有一个价格, 《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】 还有一个折扣,那么手机的实际价格就是当前价*折扣,我们现在就想要查看实际的价格该怎么办呢?表里面根本没有实际价格这个字段,这时我们就可以对多个列进行算术运算了。
多个列执行运算的格式为 列名1 运算符 列名2… as 新列名 ,为了增强语义性,可以使用一个括号把运算的列包起来。
现在,我们来通过计算查看手机的实际价格
select * ,(price * discount) as ‘实际价格’ from cellphone;

我们使用列来进行计算就得出了当前实际价格,但是我们发现实际价格小数特别多,我们可不可以只保留2位小数呢?肯定是可以的,在后面我们使用函数就能实现,这里就先不介绍。
边栏推荐
- rk3399 gpio口 如何查找是哪个gpio口
- Amazon evaluation autotrophic number, how to carry out systematic learning?
- The main advantage of face brushing payment users is their high degree of intelligence
- Deploy redis with docker for high availability master-slave replication
- In the future, face brushing payment can occupy a lot of market share
- 刷脸支付更符合支付宝一直做生态的理念
- kettle的文件名通配规则
- 2021中大厂php+go面试题(2)
- MySQL如何执行查询语句
- 刷脸支付永远不会过时只会不断的变革
猜你喜欢

Day14. 用可解释机器学习方法鉴别肠结核和克罗恩病

How does gamefi break the circle? Aquanee shows its style by real "p2e"

If you encounter oom online, how to solve it?

Choose a qualified futures company to open an account

我想不通,MySQL 为什么使用 B+ 树来作索引?

jenkins构建镜像自动化部署

Mysql5.7版本如何实现主从同步

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

inno setup 打包 jar + h5 + mysql + redis 成 exe

When opening futures accounts, you should discuss the policy in detail with the customer manager
随机推荐
2022-07-26 第四小组 抽象类、接口
golang中slice切片使用的误区
期货开户公司交返怎么申请?
Es time query error - "caused_by": {"type": "illegal_argument_exception", "reason": "failed to parse date field
舆情&传染病时空分析文献阅读笔记
MySQL索引分析除了EXPLAIN还有什么方法
存储过程试炼1--爱的初相识
Jenkins build image automatic deployment
GBASE 8C——SQL参考6 sql语法(12)
神芷迦蓝寺
Several ways of element positioning in page layout
本地ORACLE报ORA-12514: TNS:监听程序当前无法识别请求服务
哪个期货公司手续费低高交返?
Emoji表情符号用于文本情感分析-Improving sentiment analysis accuracy with emoji embedding
原油期货开户条件和流程是什么?
How can seektiger go against the cold air in the market?
难道Redis真的变慢了吗?
RK3288板卡HDMI显示uboot和kernel的logo图片
php 定义数组使用逗号,
rk3399 gpio口 如何查找是哪个gpio口