首页 > 试题广场 >

Mysql中表student_table(id,name,b

[单选题]
Mysql中表student_table(id,name,birth,sex),查询name重复的id最大的记录,比如'张三'重复2次,id分别是1、2,则结果是id=2的记录。如下SQL错误的是()?
  • select t4.*
    from (
    select t2.*
    from
    (select name,count(*) as c1 from student_table GROUP BY name having c1 > 1)t1
    inner join
    (select name, max(id) as id from student_table group by name ) t2
    on t1.name = t2.name
    )t3
    right join
    student_table t4
    on t3.id = t4.id ;
  • select t4.*
    from (
    select t2.*
    from
    (select name,count(*) as c1 from student_table GROUP BY name having c1 > 1)t1
    inner join
    (select name, max(id) as id from student_table group by name ) t2
    on t1.name = t2.name
    )t3
    inner join
    student_table t4
    on t3.id = t4.id ;
  • select t4.*
    from (
    select t2.*
    from
    (select name,count(*) as c1 from student_table GROUP BY name having c1 > 1)t1
    inner join
    (select name, max(id) as id from student_table group by name ) t2
    on t1.name = t2.name
    )t3
    left join
    student_table t4
    on t3.id = t4.id ;
  • select t4.*
    from (
    select t2.*
    from
    (select name,count(*) as c1 from student_table GROUP BY name having c1 > 1)t1
    left join
    (select name, max(id) as id from student_table group by name ) t2
    on t1.name = t2.name
    )t3
    left join
    student_table t4
    on t3.id = t4.id ;
这题让我崩溃了
发表于 2022-02-22 18:50:25 回复(3)
为什么要这么写代码
发表于 2022-01-27 11:00:03 回复(2)
两个left所以排除left,inner可以和right/left转换,所以选A,从数据分析答案
发表于 2022-05-09 12:47:03 回复(0)
A right join的话是以student_table为主表,因此最后的记录和student_table记录数一样
发表于 2022-03-06 05:42:22 回复(0)
我懂你,这时候看这个SQL能让你舒服 select name, max(id) as max_id from student_table where name in( select name from student_table grouo by name having count (*)>1 ) group by name;
发表于 2023-12-14 10:55:38 回复(0)
为什么要 从 select t2.*里面再select t4.*
发表于 2022-09-21 21:01:08 回复(0)
t1:按名字分组限定为出现次数大于1的数据 ---->namecount--->出现次数大于1的名字 t2:按名字分组,查找id的最大值---->namemax(id)--->每个名字的id最大值 t3:内连接t1t2,筛选名字相同的---->name countmax(id)--->出现次数大于1的名字对应的id最大值 t4:重命名的原表 右连接t3t4,返回了t4对应的结果,会有重复数据
发表于 2023-08-28 15:13:16 回复(0)
包含关系图如图所示
发表于 2022-06-12 11:03:49 回复(0)
这题不是选C吗
发表于 2022-01-13 22:42:09 回复(1)
A中【right join 】是以右表为主表,结果会包含name不重复的记录,则A错误。
发表于 2022-05-23 17:05:05 回复(0)
这道题重点考察表的左外连接,右外连接,内连接;关于这道题目,一个比较直观的解题思路是从数学集合的角度进行求解,或者上网寻找维恩图即可
发表于 2022-05-18 11:38:02 回复(0)
原来是找错误的一项,我吐了😂
发表于 2022-04-13 17:59:03 回复(1)
蹲一个一起学习的小伙伴 +v:sobiubalabala
发表于 2021-12-25 11:42:45 回复(0)
好长的题目(尖叫)
发表于 2024-05-01 15:56:20 回复(0)
有没有人解释下为什么要和t4弄最后的left join,前面求出的不就是名字和最大值id了吗
发表于 2024-04-20 15:55:42 回复(0)
练了一些leetcode题目看这种写法简直是灾难
发表于 2024-03-29 10:46:17 回复(0)
看了半天,看到个select from t4.* 然后又有个right join t4 果断选A
发表于 2023-07-28 11:58:50 回复(0)
看晕了,这种问题真的不是恶心人的吗?

发表于 2022-11-09 12:47:15 回复(0)
D答案有谁解释一下吗
发表于 2022-08-31 12:54:41 回复(0)
为什么最后是 on t3.id = t4.id 
不应该是 on t3.id=t.id 嘛?
发表于 2022-07-24 22:37:58 回复(1)