mysql-sql-第十四周

学习目标:

sql

学习内容:

40.查询学过「哈哈」老师授课的同学的信息

Select * from students left join score on students.stunm=score.stunm where counm = (select counm from teacher left join course on teacher.teanm=course.teanm where teacher.name= '哈哈');

出现错误

ERROR 1241 (21000): Operand should contain 1 column(s)

是MySQL数据库中的一个常见错误。这个错误发生的原因通常是在你尝试在期望一个列值的地方使用了一个返回多列的子查询或者函数。

修改后

Select * from students left join score on students.stunm=score.stunm where counm = (select counm from teacher left join course on teacher.teanm=course.teanm where teacher.name= '哈哈');

出现错误

ERROR 1242 (21000): Subquery returns more than 1 row

*这个错误发生在SQL查询中,当子查询返回多于一行结果时,而父查询期望子查询返回单行结果时就会出现这个错误。在SQL中,子查询通常用在WHERE或SELECT列表中,并期望返回一个标量值(单个值)

换一种方式

select students.* from students,teacher,course,score

where students.stunm = score.stunm and course.counm=score.counm and course.teanm = teacher.teanm and teacher.name = '哈哈';

学习时间:

1月-3月,每天一小时左右

学习产出:

一周一发

相关推荐
椰羊~王小美1 小时前
存储过程 vs 存储函数:全面对比
数据库
张人玉1 小时前
SQLite的数据格式和使用命令
数据库·oracle·sqlite
last demo1 小时前
MariaDB 数据库管理
linux·运维·服务器·数据库·php·mariadb
SamDeepThinking1 小时前
在 MySQL 里,不建议使用长事务的根因
后端·mysql
蒋士峰DBA修行之路1 小时前
实验二十六 GaussDB参数调优
数据库·oracle·gaussdb
q***3751 小时前
MySQL输入密码后闪退?
数据库·mysql·adb
张人玉1 小时前
SQLite 快速入门 Cheat Sheet
数据库·sql·sqlite
杨DaB1 小时前
【MySQL】03 数据库的CRUD
数据库·mysql·adb
DarkAthena1 小时前
【DuckDB】活用marco以兼容GaussDB的SQL执行
数据库·sql·duckdb
沐浴露z2 小时前
一张思维导图理清【Redis】
数据库·redis·缓存