如何在SQL中编写以下查询

时间:2016-12-03 12:23:52

标签: sql postgresql

我的桌子:
音乐家(id,mname,aname,百分比(年龄费用))
歌手(身份证,性别)
乐器演奏家(id,乐器)
代理人(aname,street,city,zip)
节日(标题,地点,日期,编辑)
事件(标题,edate,etime)
已预订(ID,标题(Event.title),edate,etime,salary)

  1. 每个节日,找到代理商,这个节日的整体利润是最高的。提供了电影节的名称,代理商名称及其整体利润。

  2. Festival.title =&#34;秋节&#34;和工资<8000, 查找仅参加活动的日期和时间 乐器演奏者,此次活动的乐器演奏者人数最少。

  3. 1

    select f1.title , aname , sum (salary*percentage/100) as feeAgent 
    from festival as f1 , booked , musician 
    where booked.id=musician.id and booked.edate between f1.sdate and f1.edate
    group by  f1.title , aname
    having sum (salary*percentage/100)>any(select sum (salary*percentage/100)
                                           from festival as f1 , booked , musician 
                                           where booked.id=musician.id and     booked.edate between f1.sdate and f1.edate
                                           group by musician.aname)
    

    2

    select event.edate, event.etime
    from event, festival as f1, booked natural join musician natural join instrumentalist 
    where event.title=f1.title and f1.title Like 'spring%' and booked.salary<8000 and booked.edate between f1.sdate and f1.edate
    group by event.edate, event.etime
    having count(booked.title)<all(select count(*)
               from event,festival as f1,booked natural join musician natural join instrumentalist
               where event.title=f1.title and f1.title Like 'spring%' and booked.salary<8000 and booked.edate between f1.sdate and f1.edate
               group by booked.title)
    

0 个答案:

没有答案