当前位置:网站首页>Getting started database days3
Getting started database days3
2022-07-23 22:47:00 【Xiao Wu has an idea】
- Reference books 《MySql From entry to mastery 》
- Learning video 【 Han Shunping said MySQL】 Zero basis a week to learn MySQL -sql mysql course mysql video mysql introduction _ Bili, Bili _bilibili
- Mengxin beginner level , If there is any mistake, please give advice , Not very grateful
Catalog
Use group by Clause to group Columns [ First create the test table ]
Statistical function -count
Count Returns the total number of rows
Select count(*) | count( Name ) from Table name
[WHERE where_definition]
example : Count how many students there are in a class
![]()

The total score of statistics is greater than 260 How many students are there


count(*) and count( Column ) The difference between
- count(*) Return the number of rows of records that meet the conditions
- count( Column ): Count the number of columns that meet the conditions , But it will be excluded as null The situation of
example :
CREATE TABLE t10(
`name` VARCHAR(20));
INSERT INTO t10 VALUES('tom');
INSERT INTO t10 VALUES('jack');
INSERT INTO t10 VALUES('mary');
INSERT INTO t10 VALUES(NULL);
SELECT * FROM t10;Create a table t10, Use them separately count(*) and count(`name`) Inquire about
![]()


One is 4 One is 3
Aggregate function Sum
Select sum( Name ) {,sum( Name )...} from Table name
[WHERE where_definition]
example : Count the total score of a class
![]()
Count the total scores of each subject of mathematics, English and Chinese in a class 

Count the average score of a class in Mathematics


Sum Value only , If it is sum(`name`) It doesn't make sense
Aggregate function AVG
AVG The function returns a value that satisfies where The average of a column of conditions
Select avg( Name ) {,avg( Name )...} from Table name
[WHERE where_definition]
example : Find the average math score of a class


Aggregate function ——MAX/MIN
Select max( Name ) {,avg( Name )...} from Table name
[WHERE where_definition]
example : Ask for the highest and lowest scores of students in the class


Grouping statistics
Use group by Clause to group Columns [ First create the test table ]
SELECT column1,column2 . column3... FROM table
group by column ( Filter )having ...
Continue to use our monster table
Press image To query the average salary and maximum salary of monsters in groups


Filter ( Use having), Only show that the average salary is less than 4000 Of

Show each image Average salary and maximum salary of each position in


String function
example : Returns the substring character set

The substring character set is the default utf8
example : Connection substring , Splice multiple columns into one column

example :INSTR(string,substring) return substring stay string Where in , No return 0( You can use the system when you don't have a watch DUAL surface )

example :UCASE(string)( Convert to uppercase )

Empathy LCASE(string) Convert to lowercase
example :LEFT(string,length) from string To the left of length Characters


example :LENGHT(string) string length ( Press byte )



Here are monsters and monsters 001 The length of each of them is 9, Because a Chinese character here accounts for 3 Bytes (utf8)
example :replace(str,s1,s2) stay str of use s2 Replace s1
Here I will monster 003 Replace with monsters 004

example :STRCMP(string1,string2) , Compare the size of two strings character by character



example :SUBSTRING(str,a,b) from a Began to intercept str Of b Characters


example : Remove front-end or back-end spaces LTRIM(string) RTRIM(string) TRIM(string)

3 The result of both cases is the same , In the end " The database between my fingers was destroyed "
practice : Display all employees in lowercase emp The name of the table
SELECT CONCAT(LACSE(SUBSTRING(ename,1,1),SUBSTRING(ename,2)) from emp;Mathematical functions

example :ABS(num) The absolute value

example :BIN(num) 10 Turn into the system 2 Base number

example :CEILING(num) Return ratio num The smallest big integer

example :CONV(num1,n1,n2) take num1 from n1 Base to n2 Base number

example :FLOOR(n) Get ratio n The smallest and largest integer
example :format(n1,n2) Keep the decimal places ( rounding )

example :LEAST(n1,n2,n3...) For the minimum

example :MOD(n1,n2) Seeking remainder

example :RAND(N) Return random number , The scope is [0,1.0] , If you want random numbers to remain constant , Then write the middle n

The above is today's video notes , In case of infringement, please contact me to delete .
Learning is like sailing against the current , move forward , or you 'll fall behind . Come on with Xiao Wu !
边栏推荐
- Leetcode high frequency question 53. maximum subarray sum, continuous subarray with maximum sum, return its maximum sum
- Upgrade unity visual studio 2019 to 2022 (throw away pirated red slag)
- Rails搭配OSS最佳实践
- 使用itextpdf提取PDF文件中的任意页码
- 多线程问题:为什么不应该使用多线程读写同一个socket连接?
- MySQL的JDBC編程
- 【Matplotlib绘图】
- Mqtt connection, subscription and publishing can be realized without mqtt C library
- Extract any page number in PDF file with itextpdf
- 【golang学习笔记】flag包的简单使用,命令行解析
猜你喜欢
![[C language] address book (static version)](/img/bc/655c1176e11f66fd168c3fae01bb11.png)
[C language] address book (static version)

Microsoft SQL Server数据库语言及功能使用(十三)

Leetcode high frequency question 53. maximum subarray sum, continuous subarray with maximum sum, return its maximum sum

还在为XShell破解烦恼,试试tabby

Memory search - DP

Array - 11. Containers with the most water

What else do entrepreneurs need besides money? Exclusive interview with Mingyue Lake venture capital institutions

Programmation JDBC pour MySQL

王学岗视频编码————MediaCodec编解码

D1-h development board - Introduction to Nezha development
随机推荐
Niuke C basic exercises
STM32单片机使用ADC功能驱动手指检测心跳模块
Interface test
El upload realizes the preview of uploaded files
20. Valid parentheses valid parentheses
"Morning reading" if you were in my position, what would you do? How do we do it,
Absl tutorial (4): strings Library
Memory search - DP
Use of cjson Library
Programming in the novel [serial 19] the moon bends in the yuan universe
MySQL index transaction
Still worrying about xshell cracking, try tabby
ES6箭头函数的使用
Sword finger offer II 115. reconstruction sequence
【golang学习笔记】并发基础
MySQL的 DDL和DML和DQL的基本语法
Interface test
Leetcode high frequency question 53. maximum subarray sum, continuous subarray with maximum sum, return its maximum sum
Is Ping An Securities' low commission account opening link safe? How to handle low commission
Wangxuegang video coding -- mediacodec coding and decoding
