当前位置:网站首页>SQL Server AVG function rounding
SQL Server AVG function rounding
2022-06-24 10:09:00 【Cpsu】
SQL Sever The mean value function of is used to find whether the mean value of integer type data is the result or integer , And it doesn't round . That is, rounding down . Here, first create a grade sheet , And add data as appropriate .
CREATE TABLE sic(
Student number nchar(10) not null,
Course no. nchar(10) not null constraint pk_lh primary key( Student number , Course no. ),
achievement int not null);
INSERT INTO sic
values ('01','01',80),
('01','02',90),
('01','03',99),
('02','02',60),
('02','03',80),
('03','01',80),
('03','02',80),
('03','03',80);

SELECT AVG( achievement ) AS Divide equally
FROM sic
GROUP BY sic. Student number

Obviously, the student ID is 01 The average score of students should not be an integer . Here are two ways to solve .
The first is to set the data to... When creating the table float type .
ALTER TABLE sic
ALTER COLUMN achievement FLOAT NOT NULL;
SELECT sic. Student number ,AVG( achievement ) AS Divide equally
FROM sic
GROUP BY sic. Student number ;
# You can also use DECIMAL(18,2) Format retains two decimal places

The second way is to use SQL Server Of CAST perhaps CONVERT function .
SELECT sic. Student number ,
AVG(
CAST ( achievement AS FLOAT)
) AS Divide equally
FROM sic
GROUP BY sic. Student number
SELECT CAST(AVG(CONVERT(FLOAT, achievement )) AS DECIMAL(18,2)) AS Divide equally
FROM sic
GROUP BY sic. Student number
边栏推荐
- 十大证券公司哪个佣金最低,最安全可靠?有知道的吗
- 小程序 rich-text中图片点击放大与自适应大小问题
- 利用pandas读取SQL Sever数据表
- 411-栈和队列(20. 有效的括号、1047. 删除字符串中的所有相邻重复项、150. 逆波兰表达式求值、239. 滑动窗口最大值、347. 前 K 个高频元素)
- Get the QR code of wechat applet with parameters - and share the source code of modifying the QR code logo
- 操作符详解
- Indexeddb local storage, homepage optimization
- 正规方程、、、
- Producer / consumer model
- MySQL data advanced
猜你喜欢

TP5 using post to receive array data times variable type error: solution to array error

2021-08-17

411-栈和队列(20. 有效的括号、1047. 删除字符串中的所有相邻重复项、150. 逆波兰表达式求值、239. 滑动窗口最大值、347. 前 K 个高频元素)

SQL Sever关于like操作符(包括字段数据自动填充空格问题)

Analysis of 43 cases of MATLAB neural network: Chapter 32 time series prediction of wavelet neural network - short-term traffic flow prediction

微信小程序學習之 實現列錶渲染和條件渲染.

Go language development environment setup +goland configuration under the latest Windows

CVPR 2022 oral | NVIDIA proposes an efficient visual transformer network a-vit with adaptive token. The calculation of unimportant tokens can be stopped in advance

机器学习——感知机及K近邻

Floating point notation (summarized from cs61c and CMU CSAPP)
随机推荐
SQL statistics of users logged in for N consecutive days
顶刊TPAMI 2022!基于不同数据模态的行为识别:最新综述
How does home office manage the data center network infrastructure?
tf.errors
静态链接库和动态链接库的区别
416 binary tree (first, middle and last order traversal iteration method)
Graffiti smart brings a variety of heavy smart lighting solutions to the 2022 American International Lighting Exhibition
numpy.logical_and()
队列Queue
英伟达这篇CVPR 2022 Oral火了!2D图像秒变逼真3D物体!虚拟爵士乐队来了!
小程序学习之获取用户信息(getUserProfile and getUserInfo)
port 22: Connection refused
Record the range of data that MySQL update will lock
大中型企业如何构建自己的监控体系
2021-08-17
机器学习——感知机及K近邻
SQL Sever中的窗口函数row_number()rank()dense_rank()
有关二叉树 的基本操作
为什么 JSX 语法这么香?
js代理模式