笔试直接被拒绝,说没通过,然后.........

tingyingg 2016-09-01 11:03:40
麻痹的,笔试让老子写编程题就算了, 桌子还和椅子一样高(多个10厘米左右), 重点是我本来写字就不好看了,还来个这么难堪的环境, 这不是更丑了嘛,重点是后两道题也不会做呀。

create table TCustomer(cid integer primary key, name varchar2(20), age integer); -- // 客户表: 主键, 名字,年龄
create table TBook(bid integer primary key, name varchar2(20), price integer); --// 书籍表 主键, 书名, 价格
create table TOrder(oid integer primary key, bid integer, cid integer); --- 订单表 : 主键, 书籍ID, 客户ID。

这三张表 , 求出在 20 - 30 岁年龄段中最受欢迎的书本。

做不出来也不算菜比吧, 还是手写 ,搞得我后面都没信心去面试了。

所以请教一下兄弟们,这道题怎么破呢?
...全文
1738 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
computerclass 2016-09-12
  • 打赏
  • 举报
回复
IN效率有点低。。。
tingyingg 2016-09-09
  • 打赏
  • 举报
回复
引用 10 楼 qq715787268 的回复:
看一眼就知道两个子查询搞定
求大神普及两分钟,感激不尽,IN和 exists 差别那么大吗? 网上说也不一定
EP外星人 2016-09-07
  • 打赏
  • 举报
回复
这种表统计,敢用IN,凡是用in的统统面试不过!
qq715787268 2016-09-07
  • 打赏
  • 举报
回复
看一眼就知道两个子查询搞定
nanjun520 2016-09-05
  • 打赏
  • 举报
回复
引用 8 楼 tingyingg 的回复:
[quote=引用 2 楼 nanjun520 的回复:]

slelect bid ,max(Count(*))  from TOrder where cid  in(
         slelect cid from TCustomer where age >20 and age <30)group by bid
) as tmpA INNER JOIN TBook  where bid =tmpA .bid 
没验证
thanks, 但我看没错的话,好像只是显示了所有的书,并没有选出最受欢迎的书。 [/quote] slelect bid ,max(Count(*)) from TOrder where cid in( slelect cid from TCustomer where age >20 and age <30)group by bid ) 这个就是最喜欢的书的 bid
tingyingg 2016-09-04
  • 打赏
  • 举报
回复
引用 2 楼 nanjun520 的回复:

slelect bid ,max(Count(*))  from TOrder where cid  in(
         slelect cid from TCustomer where age >20 and age <30)group by bid
) as tmpA INNER JOIN TBook  where bid =tmpA .bid 
没验证
thanks, 但我看没错的话,好像只是显示了所有的书,并没有选出最受欢迎的书。
tingyingg 2016-09-04
  • 打赏
  • 举报
回复
引用 2 楼 nanjun520 的回复:

slelect bid ,max(Count(*))  from TOrder where cid  in(
         slelect cid from TCustomer where age >20 and age <30)group by bid
) as tmpA INNER JOIN TBook  where bid =tmpA .bid 
没验证
thanks, 但我看没错的话,好像只是显示了所有的书,并没有选出最受欢迎的书。
qq_35173063 2016-09-02
  • 打赏
  • 举报
回复
引用 4 楼 meng3000 的回复:
楼上的写法错误,TCustomer TBook 两张表没有关联,直接两个子查询: select * from TBook where id = (select top 1 bid (select bid,count(bid) as num from from TOrder where cid in (select cid from TCustomer where age between 20 and 30 )group by bid order by num desc )) 手写的,可能细节有点问题,但是思路对
三张表两两关联,有问题么?
meng3000 2016-09-02
  • 打赏
  • 举报
回复
楼上的写法错误,TCustomer TBook 两张表没有关联,直接两个子查询: select * from TBook where id = (select top 1 bid (select bid,count(bid) as num from from TOrder where cid in (select cid from TCustomer where age between 20 and 30 )group by bid order by num desc )) 手写的,可能细节有点问题,但是思路对
qq_35173063 2016-09-02
  • 打赏
  • 举报
回复
select distinct TBook.name from TCustomer,TOrder,TBook where TCustomer.cid=TOrder.cid and TOrder.bid=TBook.bid and TCustomer.age between 20 and 30
nanjun520 2016-09-02
  • 打赏
  • 举报
回复

slelect bid ,max(Count(*))  from TOrder where cid  in(
         slelect cid from TCustomer where age >20 and age <30)group by bid
) as tmpA INNER JOIN TBook  where bid =tmpA .bid 
没验证

662

社区成员

发帖
与我相关
我的任务
社区描述
提出问题
其他 技术论坛(原bbs)
社区管理员
  • community_281
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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