谁帮我做下下面三道题 做不出来啊

pps230 2012-10-20 05:35:27
Sailors(sid:integer, sname:string, rating:integer, age:real)
Boats(bid:integer, bname:string, color:string)
Reserves(sid:integer, bid:integer, day:date)
Sailors(水手表)
sid编号 same名字 rating等级 age年龄
22 Dustin 7 45.0
29 Brutus 1 33.0
31 Lubber 8 55.5
32 Andy 8 25.5
58 Rusty 10 35.0
64 Horatio 7 35.0
71 Zorba 10 16.0
74 Horatio 9 35.0
85 Art 3 25.5
95 Bob 3 63.5
Reserves(预订情况表)
sid水手编号bid船只编号day日期
22 101 10/10/98
22 102 10/10/98
22 103 10/8/98
22 104 10/7/98
31 102 11/10/98
31 103 11/6/98
31 104 11/12/98
64 101 9/5/98
64 102 9/8/98
74 103 9/8/98
Boats(船只表)
bid编号 bname名字 color颜色
101 Interlake blue
102 Interlake red
103 Clipper green
104 Marine red




1.对于至少有两个水手的等级级别,求出水手们的平均年龄
2.对于至少有两个水手的等级,找出到了投票年龄(至少有18岁)的所有水手的平均年龄
3.找出在所有的等级中水手的平均年龄是最低的那些等级
...全文
102 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
DBA_磊仔 2012-10-20
  • 打赏
  • 举报
回复
--构建示例数据 drop table Sailors
Create TABLE Sailors (sid int,same varchar(50),rating int,age numeric(32,2))
INSERT INTO Sailors select '22', 'Dustin', '7', '45.0'
union all select '29', 'Brutus', '1', '33.0'
union all select '31', 'Lubber', '8', '55.5'
union all select '32', 'Andy', '8', '25.5'
union all select '58', 'Rusty', '10', '35.0'
union all select '64', 'Horatio', '7', '35.0'
union all select '71', 'Zorba', '10', '16.0'
union all select '74', 'Horatio', '9', '35.0'
union all select '85', 'Art', '3', '25.5'
union all select '95', 'Bob', '3', '63.5'

--方案
--1.对于至少有两个水手的等级级别,求出水手们的平均年龄
select rating,AVG(age) avgage from Sailors group by rating having COUNT(same) >= 2
/*rating avgage
----------- ---------------------------------------
3 44.500000
7 40.000000
8 40.500000
10 25.500000

(4 行受影响)

*/
--2.对于至少有两个水手的等级,找出到了投票年龄(至少有18岁)的所有水手的平均年龄
select rating,AVG(age) avgage from Sailors
where rating in(select rating from Sailors group by rating having COUNT(same) >= 2)
and age >= 18 group by rating
/*
rating avgage
----------- ---------------------------------------
3 44.500000
7 40.000000
8 40.500000
10 35.000000

(4 行受影响)


*/
--3.找出在所有的等级中水手的平均年龄是最低的那些等级
select TOP(1) rating,AVG(age) avgage from Sailors group by rating ORDER BY AVG(age)
/*rating avgage
----------- ---------------------------------------
10 25.500000

(1 行受影响)

*/

34,837

社区成员

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

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