查询累计人流量大于30的地点名称和累计人流量,累积人流量请用visitors作标题名称。
查询结果按照人流量从高到低排序,人流量相同时,依地点名称顺序排序。
注意:同一人多次逛同一地点,去几次算几次)
请用一条SQL语句实现该查询:
select location_name,count(*) visitors from location,itinerary
where location.id=itinerary.loc_id
group by loc_id
having visitors>30
order by visitors desc,location_name;
查询每个隔离地及该地正在进行隔离的人数,以number为隔离人数的标题.
查询结果依隔离人数由多到少排序。人数相同时,依隔离地点名排序。
请用一条SQL语句实现该查询:
select location_name,count(*) number from isolation_record,isolation_location
where isolation_record.isol_loc_id=isolation_location.id and state=1
group by isolation_location.id
order by number desc,location_name;
查询行程表中所有属于同一个人的接续行程信息。输出内容包括:
人员编号,姓名,重合时间,起始地点id,起始地点,结束地点id,结束地点。
查询结果依人员编号排序。
请用一条SQL语句实现该查询:
select
p.id id,
fullname,
telephone,
i1.e_time reclosing_time,
i1.loc_id loc1,
l1.location_name address1,
i2.loc_id loc2,
l2.location_name address2
from itinerary i1,itinerary i2,location l1,location l2,person p
where i1.e_time=i2.s_time and i1.p_id=i2.p_id and i1.loc_id=l1.id and i2.loc_id=l2.id and p.id>30 and p.id=i1.p_id
order by p.id,reclosing_time;
查询充珉瑶和贾涵山的行程情况。查询结果包括:姓名、电话、到过什么地方(地名),何时到达,何时离开 。
列名原样列出,不必用别名。查询结果依人员编号降序排序。
请用一条SQL语句实现该查询:
use covid19mon;
select fullname,telephone,location_name,s_time,e_time
from person
left join itinerary on person.id=itinerary.p_id
left join location on location.id=itinerary.loc_id
where fullname='充珉瑶' or fullname='贾涵山'
order by person.id desc,s_time;
查询地名中带有‘店’字的地点编号和名称。查询结果按地点编号排序。
请用一条SQL语句实现该查询:
use covid19mon;
select id,location_name from location
where location_name like '%店%'
order by id;
新发现一位确诊者,已知他在2021.2.2日20:05:40到21:25:40之间在“活动中心”逗留,
凡在此间在同一地点逗留过的,视为接触者,请查询接触者的姓名和电话。查询结果按姓名排序.
请用一条SQL语句实现该查询:
use covid19mon;
select distinct fullname,telephone
from itinerary
join person on person.id=itinerary.p_id
join location on location.id=itinerary.loc_id
where location_name='活动中心'
and s_time < '2021-02-02 21:25:40'
and e_time > '2021-02-02 20:05:40'
order by fullname;
查询正在使用的隔离点名,查询结果按隔离点的编号排序。
请用一条SQL语句实现该查询:
use covid19mon;
select location_name from(select distinct isolation_location.id,location_name
from isolation_location
join isolation_record
on isolation_location.id = isolation_record.isol_loc_id
where state=1
order by isolation_location.id) q;
用一条带exists关键字的SQL语句查询前30位有出行记录的人员姓名和电话。查询结果按照人员编号排序。
请用一条SQL语句实现该查询:
use covid19mon;
select fullname,telephone
from person
where exists(
select * from itinerary
where person.id<=31 and p_id=person.id
)
order by person.id;
写一条带NOT EXISTS 子查询的SQL语句实现下述查询要求:
查询人员表中没有去过地点“Today便利店”的人数。请给统计出的人数命名为number。
请用一条SQL语句实现该查询:
use covid19mon;
select count(*) number
from person
where not exists(
select * from location
join itinerary on location.id=itinerary.loc_id
where location_name='Today便利店' and itinerary.p_id=person.id
);
查询人员表中去过所有地点的人员姓名。查询结果依人员姓名顺序排序。
请用一条SQL语句实现该查询:
use covid19mon;
select fullname from person
where not exists(
select * from location
where location.id not in(
select loc_id from itinerary
where itinerary.p_id=person.id
)
)
order by fullname;
建立反映所有隔离点现状的视图isolation_location_status。
内容包括:地点编号,隔离地点名,房间容量,已占用量
请保持原列名不变,已占用量由统计函籹计算得出,该列命名为occupied。
正在隔离的人占用着隔离点的位置,隔离结束或已转院的人不占用位置。
use covid19mon;
CREATE VIEW isolation_location_status AS
SELECT
isolation_location.id AS id,
isolation_location.location_name,
isolation_location.capacity,
COUNT(CASE WHEN isolation_record.state = 1 THEN 1 ELSE NULL END) AS occupied
FROM
isolation_location
JOIN
isolation_record ON isolation_record.isol_loc_id = isolation_location.id
GROUP BY
isolation_location.id,
isolation_location.location_name,
isolation_location.capacity;
从视图isolation_location_status中查询各隔离点的剩余空房间的数目。
需要列出的数据项:隔离点名称,剩余房间数。其中剩余房间数为计算得出,请给该列命名为available_rooms
查询结果依隔离点编号排序。
请用一条SQL语句实现该查询:
use covid19mon;
select location_name,capacity-occupied available_rooms
from isolation_location_status;
筛查发现,靳宛儿为无症状感染者。现需查询其接触者姓名名单和电话,以便通知并安排隔离。查询结题按姓名排序。
凡行程表中,在同一地点逗留时间与靳宛儿有交集的,均视为接触者。
请用一条SQL语句实现该查询:
use covid19mon;
select fullname,telephone
from itinerary,person,(select loc_id,s_time,e_time
from itinerary
join person on person.id=itinerary.p_id
where fullname='靳宛儿') as scl
where person.id=itinerary.p_id and itinerary.loc_id=scl.loc_id
and itinerary.s_timescl.s_time
and fullname<>'靳宛儿'
order by fullname;
依据密切接触表的内容查询每个地点的密切接触者的数量,列出内容包括:地点名称,密接者人数。
人数由统计获得,列名命名为close_contact_number.查询结果依密接者人数降序排列。
密接者人数相同时,依地点名称排序。
请用一条SQL语句实现该查询:
use covid19mon;
select location_name,count(*) close_contact_number
from location
join close_contact on location.id=close_contact.loc_id
group by location_name
order by close_contact_number desc,location_name;
查询感染人数最多的人员编号,姓名,和被其感染的人数。
感染人数由统计所得,命名为infected_number.
-- 说-明:
由于数据集close_contact表中的被密接者大多无诊断记录(无法知晓其是否被感染)。
增补数据集会影响其它评测,更有同学此前已完成评测。所以,此题暂简化为被密接者就是感染者。
请用一条SQL语句实现该查询:
use covid19mon;
select case_p_id,fullname,count(*) infected_number
from person,close_contact
where person.id=close_contact.case_p_id
group by case_p_id,fullname
order by infected_number desc
limit 1;
查询2021-02-02 10:00:00到14:00:00期间,行程记录最频繁的3个人的姓名及行程记录条数。
记录条数命名为record_number. 记录数并列的,按姓名顺序排列。
请用一条SQL语句实现该查询:
use covid19mon;
select fullname,count(*) record_number
from person
join itinerary on person.id=itinerary.p_id
where s_time<='2021-02-02 14:00:00'
and e_time>='2021-02-02 10:00:00'
group by fullname
order by record_number desc,fullname
limit 3;
查询隔离点中,房间数第二多的隔离点名称和房间数。
请用一条SQL语句实现该查询:
use covid19mon;
select location_name,capacity
from isolation_location
where capacity<(
select max(capacity) from isolation_location
)
limit 1;