你真的懂SQL语句的编写吗?快来,我给你分

kingdomzhf 2002-08-22 11:38:12
以下有几个问题(用一条SQL语句写出来):
一个表student(name(学生姓名),score(分数)),查出最高三个分数对应的记录(请考虑多个人有相同的分数)
一个表student(class(班级),name(学生姓名),sex(f,m)),查出男女同学相同的班级
另外哪位大虾有深入讲解SQL的书籍或网络资源,请告知
...全文
44 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
dejoy 2002-08-25
  • 打赏
  • 举报
回复
是啊,如果有四.五个100分,怎么办?第4第5个就不要了?
建议修改一下表结构,增加一个学号字段,一个班级号字段,都是唯一的,建三个表
学生(学号,姓名,性别,班级号,……)
班级(班级号,班级名称,班主任,……)
分数(学号,分数,……)
icbczks 2002-08-25
  • 打赏
  • 举报
回复
如果很好的解决这个问题,我认为还是考虑变化一下数据结构.
zouzhichang 2002-08-23
  • 打赏
  • 举报
回复
如果有四个100分呢?为什么要最高分三个呢?可以同一个记录最高分三个吧!
kingdomzhf 2002-08-22
  • 打赏
  • 举报
回复
to:erickleung()
书上的语法很简单,但与实际还是有差距
至少要复杂一点
given 2002-08-22
  • 打赏
  • 举报
回复
select * from student where score in (select top 3 * from (select distinct score from student)as a order by a.score desc)
kingdomzhf 2002-08-22
  • 打赏
  • 举报
回复

是男女同学数目相同的班级

你的AN INTORDUCTION TO DATEBASE SYSTEM 在哪有
erickleung 2002-08-22
  • 打赏
  • 举报
回复
select name, score from student where score in
(select distinct top 3 score from student)
order by score desc

查出男女同学相同的班级??? 不明白你想找甚應.

我是用 An Introduction to Database System (C.J. Date)
每個 sql server都會詳細解釋的sql語法.

balloonman2002 2002-08-22
  • 打赏
  • 举报
回复
select top 3 字段名 from 表名

这样的语句在SYBASE数据库中好象不能用啊,:)
chenguohui 2002-08-22
  • 打赏
  • 举报
回复
ftp.xjtu.edu.cn
supsuccess 2002-08-22
  • 打赏
  • 举报
回复
有意思,再来:
select class
from student
group by class
having sum(case sex when 'f' then 1 else -1 end)=0
caiyunxia 2002-08-22
  • 打赏
  • 举报
回复
1见上
2 提select class
from student
group by class
having sum(case when sex ='f' then 1 else 0 end)=sum(case when sex='m' then 1 else 0 end)
supsuccess 2002-08-22
  • 打赏
  • 举报
回复
1.
select * from student t1,(select top 3 score from student group by score order by score desc)t2
where t1.score=t2.score
2.
select class
from student
group by class
having sum(case sex when 'f' then 1 else 0 end)=sum(case sex when 'm' then 1 else 0 end)
balloonman2002 2002-08-22
  • 打赏
  • 举报
回复
1、学习,原来TOP还可以这么用,:)
2、我猜的,估计不行,:):
select a.class from student a,student b
where (a.class=b.class) and (count(a.name)=count(b.name))
and (a.sex="m" and b.sex="f")

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧