查看: 1264| 回复: 7
跳转到指定楼层
上一主题 下一主题
收起左侧

请教一个sql题

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
Write a query that returns the name of each department and a count of the number of employees in each: -baidu 1point3acres
EMPLOYEES containing: Emp_ID (Primary key) and Emp_Name. 1point3acres.com
EMPLOYEE_DEPT containing: Emp_ID (Foreign key) and Dept_ ID (Foreign key)
DEPTS containing: Dept_ID (Primary key) and Dept_Name

Solution 1:
select Dept_Name, count(1) from DEPTS a right join EMPLOYEE_DEPT b on a.Dept_id = b.Dept_id group by Dept_Name
Solution 2:.google  и
Select  De.Dept_Name count(Em.Emp_ID)
From  DEPTS asDe. check 1point3acres for more.
inner Join EMPLOYEE_DEPT as Em
On De.Dept_ID=Em.Dept_ID
Group by Dept_Name


solution 2 对吗?

上一篇:请问有人面过Thumbtack的Product Analyst吗?
下一篇:很好奇业界的data scientist的生活是啥样的?
全局:
感觉没什么问题,甚至觉得比#1要好
回复

使用道具 举报

🔗
 楼主| fangfang20 2018-11-4 14:41:28 | 只看该作者
全局:
Solution 1 是网上找的,2是我自己的,我觉得没啥问题,但我sql经验少,不知道有没有逻辑漏洞. 1point 3 acres
..
回复

使用道具 举报

🔗
 楼主| fangfang20 2018-11-4 15:25:38 | 只看该作者
全局:
Given a IMPRESSIONS table with ad_id, click (an indicator that the ad was clicked), and date, write a SQL
query that will tell me the click-through-rate of each ad by month.

Select  ad_id, count(*)
From  IMPRESSIONS. ----
Group by ad_id , month(date).google  и

这样对吗? 请大侠们指教,month(date)这样用可以吗?还有click though rate 这儿是鬼啊,每个广告只能是click次数吧。 先谢过了
回复

使用道具 举报

🔗
 楼主| fangfang20 2018-11-4 15:43:03 | 只看该作者
全局:
Given a COURSES table with columns course_id and course_name, a FACULTY table with columns faculty_id and faculty_name, and a COURSE_FACULTY table with columns faculty_id and course_id, how would you return a list of faculty who teach a course given the name of a course?. Waral dи,
Select f.faculty_name, c.course_name
From  FACULTY  as f
Natural join COURSES as c
Natural join  COURSE_FACULTY as cf.1point3acres

还有这个
回复

使用道具 举报

全局:
感觉广告那个题应该会给个定义的
回复

使用道具 举报

全局:
不是说right join很少用吗 还是我道听途说?感觉楼主的2号很好用啊
回复

使用道具 举报

全局:
Solution 1 跟2 都没错,1 用right join 是为了考虑有的employee 没有 department id 吧。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表