好像不难吗?还是我理解得太简单了?select w.* from worker w, products p where p.color='RED' AND
 p.eid = w.eid;

解决方案 »

  1.   

    You asked:how to make sure that every worker has records in this table?
    为什么要判断每个工人在这表有没有记录?没必要吧。
    一个工人如果在product表中没有记录,说明他不做任何产品,自然也不会
    做红色产品。楼上语句完全可以解决(1)的问题,是不是难的在后面?
      

  2.   

    题目的意思应是这个工人必须生成所有的红色产品(而不是部分红色产品),楼上的SQL只能列出生产红色产品的工作
      

  3.   

    果真是我想简单了,这才有点难度,瞧瞧下面的SQL:select w.* from worker w, 
    (select eid, count(distinct pid) pid_num from products
     where color='RED' group by eid ) a,
    ( select count(distinct pid) pid_num from products 
      where color='RED') b
    where a.pid_num = b.pid_num and w.eid = a.eid;
    select eid, count(distinct pid) pid_num from products
    对pid之所以使用distinct,是因为不知到products表的主键是什么,
    估计count(*)也可以。