当前位置:网站首页>MySQL keyword group_ Concat, combined connection query
MySQL keyword group_ Concat, combined connection query
2022-04-23 03:16:00 【Xiaodaoxian 97】
One 、
Try to think about what to do if there is such a need :
There is a student list , And a score sheet . To find out the name and score of each student , Fractions are separated by commas
eg: Zhang San 80,90,100
This demand is very simple , There are many ways to solve , The simplest thing is that we can query the students first , Then check the score , Finally, it is assembled by program code .
Student list (stu)
id | name |
---|---|
1 | Zhang San |
2 | Li Si |
3 | Wang Wu |
Score table (course)
id | name | stu_id | score |
---|---|---|---|
1 | Chinese language and literature | 1 | 80 |
2 | mathematics | 1 | 90 |
3 | English | 1 | 75 |
4 | Chinese language and literature | 2 | 55 |
5 | mathematics | 2 | 45 |
6 | English | 3 | 90 |
Two 、
But some time ago, a friend recommended MySql keyword group_concat, It's easy to use this keyword .
SELECT
s.name name,
GROUP_CONCAT(c.score) score
FROM
stu s
LEFT JOIN course c ON s.id = c.stu_id
GROUP BY s.id
3、 ... and 、
If we want to query the account name 、 fraction , And divided by semicolon, how should I write ?
SELECT
s.name name,
GROUP_CONCAT(c.name, ':',c.score separator '; ') score
FROM
stu s
LEFT JOIN course c ON s.id = c.stu_id
GROUP BY s.id
stay group_concat The fields inside , You can't do anything null, Otherwise, the whole will be null
版权声明
本文为[Xiaodaoxian 97]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230315096690.html
边栏推荐
- MySQL port is occupied when building xampp
- Experiment 6 input / output stream
- Establishing and traversing binary tree
- ASP. Net and ASP NETCORE multi environment configuration comparison
- ASP. Net 6 middleware series - conditional Middleware
- LoadRunner - performance testing tool
- How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
- [mock data] fastmock dynamically returns the mock content according to the incoming parameters
- 2022年做跨境电商五大技巧小分享
- Find the number of leaf nodes of binary tree
猜你喜欢
How does Microsoft solve the problem of multiple programs on PC side -- internal implementation
The most easy to understand dependency injection and control inversion
C read / write binary file
Chapter 9 of C language programming (fifth edition of Tan Haoqiang) analysis and answer of exercises for users to establish their own data types
[Mysql] LEFT函數 | RIGHT函數
[untitled]
[new version release] componentone added Net 6 and blazor platform control support
Experiment 5 components and event handling
2022年P气瓶充装培训试题及模拟考试
Configuration table and page information automatically generate curd operation page
随机推荐
幂等性实践操作,基于业务讲解幂等性
編碼電機PID調試(速度環|比特置環|跟隨)
Ningde's position in the times is not guaranteed?
Mysql database
“如何实现集中管理、灵活高效的CI/CD”在线研讨会精彩内容分享
Experiment 6 input / output stream
《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
. net tip: talk about the problem that the scoped service cannot be obtained in the middleware structure
js 中,为一个里面带有input 的label 绑定事件后在父元素绑定单机事件,事件执行两次,求解
General test technology [II] test method
Blazor University (11) component - replace attributes of subcomponents
The most understandable life cycle of dependency injection
Due to 3 ²+ four ²= five ², Therefore, we call '3,4,5' as the number of Pythagorean shares, and find the array of all Pythagorean shares within n (including n).
Mysql database, inconsistent index character set, slow SQL query, interface timeout
Xamarin effect Chapter 22 recording effect
The most easy to understand service container and scope of dependency injection
Use split to solve the "most common words" problem
. net core current limiting control - aspnetcoreratelimit
IDEA查看历史记录【文件历史和项目历史】
[Mysql] LEFT函數 | RIGHT函數