15-445 homework#1 sql

CS445_Homework_and_FinalProject_Share_a_Ride 立即下载

overview

主要是对如上结构的db,根据各种要求写sql

sqlite3

显示所有表格:.tables

显示表结构:.schema table_**

 

题目

Q1 [0 POINTS] (Q1_SAMPLE):

The purpose of this query is to make sure that the formatting of your output matches exactly the formatting of our auto-grading script.

Details: List all types of work ordered by type ascendingly.

本题已经给出了答案:

sqlite> select name from work_type order by name;
    Answer:
    Aria
    Audio drama
    Ballet
    Beijing opera
    Cantata
    Concerto
    Incidental music
    Madrigal
    Mass
    Motet
    Musical
    Opera
    Operetta
    Oratorio
    Overture
    Partita
    Play
    Poem
    Prose
    Quartet
    Sonata
    Song
    Song-cycle
    Soundtrack
    Suite
    Symphonic poem
    Symphony
    Zarzuela
    Etude
    

Q2 [5 POINTS] (Q2_LONG_NAME):

List works with longest name of each type.

Details: For each work type, find works that have the longest names. There might be cases where there is a tie for the longest names - in that case, return all of them. Display work names and corresponding type names, and order it according to work type (ascending) and use work name (ascending) as tie-breaker.

work的每种类型中,找出名字最长的,如果最长的有多个,那么都列出来,显示work的名字以及对应的类型名,并且按照类型排序,如果 类型(int)相同,那么按照work的名字排序

参考答案:

select work.name,
    work_type.name
from work
    inner join (
        select max(length(work.name)) as max_length,
            work.type as type
        from work
        group by work.type
    ) as newtable on newtable.max_length = length(work.name)
    and work.type = newtable.type
    inner join work_type on work.type = work_type.id
order by work.type asc,
    work.name asc;

Q3 [5 POINTS] (Q3_OLD_MUSIC_NATIONS):
List top 10 countries with the most classical music artists (born or started before 1850) along with the number of
associated artists.
Details: Print country and number of associated arists before 1850. For example, Russia|191 . Sort by number of a
in descending order.

select a2.name,
    count(*) as c
from artist a1
    inner join area a2 on a1.area = a2.id
where begin_date_year < 1850
group by a1.area
order by c desc
limit 10;

 

Q4 [10 POINTS] (Q4_DUBBED_SMASH):
List the top 10 dubbed artist names with the number of dubs.

the number of corresponding distinct dubbed artist names in the artist_alias  table. 

select a2.name,
    count(*) as c
from artist a1
    inner join area a2 on a1.area = a2.id
where begin_date_year < 1850
group by a1.area
order by c desc
limit 10;cs144@cs144vm:~/15-445/hw/hw1$ cat q4_dubbed_smash.sql 
Select artist.name,
    count(distinct artist_alias.name) as num
From artist
    inner join artist_alias on artist.id = artist_alias.artist
Where artist.begin_date_year > 1950
    and area = 221
Group by artist.id
Order by num desc
Limit 10;

Q5 [10 POINTS] (Q5_VINYL_LOVER):
List the distinct names of releases issued in vinyl format by the British band Coldplay.
Details: Vinyl format includes ALL vinyl dimensions excluding VinylDisc . Sort the release names by release date
ascendingly 

select distinct r1.name as rname
from artist_credit_name a1
    inner join artist_credit a2 on a1.artist_credit = a2.id
    inner join release r1 on a2.id = r1.artist_credit
    inner join release_info r2 on r1.id = r2.release
    inner join medium m1 on r1.id = m1.release
    inner join medium_format m2 on m1.format = m2.id
where a1.name = 'Coldplay'
    and m2.name like '%Vinyl'
order by date_year,
    date_month,
    date_day;

Q6 [10 POINTS] (Q6_OLD_IS_NOT_GOLD):
Which decades saw the most number of official releases? List the number of official releases in every decade since
1900. Like 1970s|57210 .
Details: Print all decades and the number of official releases. Releases with different issue dates or countries are
considered different releases. Print the relevant decade in a fancier format by constructing a string that looks like 
1970s . Sort the decades in decreasing order with respect to the number of official releases and use decade
(descending) as tie-breaker. Remember to exclude releases whose dates are NULL .

select distinct r1.name as rname
from artist_credit_name a1
    inner join artist_credit a2 on a1.artist_credit = a2.id
    inner join release r1 on a2.id = r1.artist_credit
    inner join release_info r2 on r1.id = r2.release
    inner join medium m1 on r1.id = m1.release
    inner join medium_format m2 on m1.format = m2.id
where a1.name = 'Coldplay'
    and m2.name like '%Vinyl'
order by date_year,
    date_month,
    date_day;cs144@cs144vm:~/15-445/hw/hw1$ cat q6_old_is_not_gold.sql 
Select decade,
    count(*) as cnt
from (
        select (CAST((date_year / 10) as int) * 10) || 's' as decade
        from release
            inner join release_info on release.id = release_info.release
        where release.status = 1
            and date_year >= 1900
    )
Group by decade
Order by cnt desc,
    decade desc;

Q7 [15 POINTS] (Q7_RELEASE_PERCENTAGE):
List the month and the percentage of all releases issued in the corresponding month all over the world in the pas
year. Display like 2020.01|5.95 .
Details: The percentage of releases for a month is the number of releases issued in that month devided by the to
releases in the past year from 07/2019 to 07/2020, both included. Releases with different issue dates or countries 
considered different releases. Round the percentage to two decimal places using ROUND() . Sort by dates in ascend
order.

with past_year_release (year, month) as (
    select date_year,
        date_month
    from release_info r1
        inner join release r2 on r1.release = r2.id
    where (
            (
                date_year = 2019
                and date_month >= 7
            )
            or (
                date_year = 2020
                and date_month <= 7
            )
        )
)
select cast(year as varchar) || '.' || (
        case
            when month < 10 then '0'
            else ''
        end
    ) || cast(month as varchar) as date,
    round(
        count(*) * 100.0 / (
            select count(*)
            from past_year_release
        ),
        2
    )
from past_year_release
group by date
order by date;

Q8 [15 POINTS] (Q8_COLLABORATE_ARTIST):
List the number of artists who have collaborated with Ariana Grande.
Details: Print only the total number of artists. An artist is considered a collaborator if they appear in the same
artist_credit with Ariana Grande. The answer should include Ariana Grande herself.

Select count(distinct artist)
From artist_credit_name
Where artist_credit in (
        select artist_credit
        from artist_credit_name
        where name = 'Ariana Grande'
    );

Q9 [15 POINTS] (Q9_DRE_AND_EMINEM):
List the rank, artist names, along with the number of collaborative releases of Dr. Dre and Eminem among other m
productive duos (as long as they appear in the same release) both started after 1960 (not included). Display like
[rank]|Dr. Dre|Eminem|[# of releases] .
Details: For example, if you see a release by A, B, and C, it will contribute to three pairs of duos: A|B|1 , A|C|1 , an
B|C|1 . You will first need to calculate a rank of these duos by number of collaborated releases (release with
artist_credit shared by both artists) sorted descendingly, and then find the rank of Dr. Dre  and Eminem . Only relea
in English are considered. Both artists should be solo artists. All pairs of names should have the alphabetically sma
one first. Use artist names (asc) as tie breaker.
Hint: Artist aliases may be used everywhere. When doing aggregation, using artist ids will ensure you get the cor
results. One example entry in the rank list is 9|Benj Pasek|Justin Paul|27

with duos_list (id1, id2, count) as (
    select a1.artist as id1,
        a2.artist as id2,
        count(*) as c
    from artist_credit_name a1
        inner join artist_credit_name a2 on a1.artist_credit = a2.artist_credit
        inner join release r on a2.artist_credit = r.artist_credit
        inner join artist a3 on a1.artist = a3.id
        inner join artist a4 on a2.artist = a4.id
        inner join artist_type a5 on a3.type = a5.id
        inner join artist_type a6 on a4.type = a6.id
        inner join language l on r.language = l.id
    where a3.name < a4.name
        and a5.name = "Person"
        and a6.name = "Person"
        and l.name = 'English'
        and a3.begin_date_year > 1960
        and a4.begin_date_year > 1960
    group by a1.artist,
        a2.artist
)
select *
from (
        select row_number () over (
                order by count desc,
                    a1.name,
                    a2.name
            ) as rank,
            a1.name as name1,
            a2.name as name2,
            count
        from duos_list d
            inner join artist a1 on d.id1 = a1.id
            inner join artist a2 on d.id2 = a2.id
    )
where name1 = 'Dr. Dre'
    and name2 = 'Eminem';

Q10 [15 POINTS] (Q10_AROUND_THE_WORLD):
Concat all dubbed names of The Beatles using comma-separated values(like " Beetles, fab four ").

with c as (
      select row_number() over (
                  order by c.id asc
            ) as seqnum,
            c.name as name
      from artist_alias c
            join artist on c.artist = artist.id
      where artist.name = 'The Beatles'
),
flattened as (
      select seqnum,
            name as name
      from c
      where seqnum = 1
      union all
      select c.seqnum,
            f.name || ', ' || c.name
      from c
            join flattened f on c.seqnum = f.seqnum + 1
)
select name
from flattened
order by seqnum desc
limit 1;

 

relay_subgraph_partition_one_slide.pptx 立即下载

相关推荐

triton-inference-server-ge-backend

新版本特性 v2.3.0 支持对全局、session、graph 的options进行添加,从而进一步调优模型,相关案例请参考 性能调优方法论。 支持采用分档模式将符合条件模型转化为静态图,提高吞吐性能。 补充如何采用分档模式+锁核+调整精度,进一步提高性能。 在AscendHub下载镜像时需确认好版本,若使用旧版本镜像,需要手工下载源码编译生成新的backend后才能支持新特性。 版本特性 v2.2.0 支持从onnx文件读取模型输入输出信息, config中若无指定input,output,将会自动从文件中读取; 调整动态图在多实例下使用多Session方式,提高并发吞吐(显存占用会增高); 支持动态batch场景小batch动态合并特性,配合多Session,提高吞吐; 补充调优方法论以及cnclip模型的最佳实践; 支持多模型特性,可支持同时拉起多个模型,提高显存利用率; 支持非0轴动态shape场景; 支持TensorFlow的pb文件。

CMU 15-445 (FALL 2022) Project #0 - C++ Primer 题解 Trie

CMU为外校的学生提供了自动测试平台和公开课,代价是什么呢?那就是不要直接公开代码在网上。还请大家遵守。这篇博客记录一些踩的坑,欢迎交流。

AntiO2的博客 3094

2007-2025年36家商业银行绿色信贷余额数据(2025年无缺失)

1、指标覆盖区间为2007年至2025年 2、数据取自各银行年度报告及社会责任报告 3、核心指标为绿色信贷余额 4、涉及银行包括:苏农银行、中国银行、紫金银行、杭州银行、华夏银行、邮储银行、青岛银行、兴业银行、苏州银行、农业银行、宁波银行、上海银行、江阴银行、招商银行、长沙银行、北京银行、无锡银行、民生银行、浙商银行、常熟银行、成都银行、工商银行、郑州银行、光大银行、南京银行、建设银行、浦发银行、贵阳银行、渝农商行、西安银行、交通银行、江苏银行、中信银行、张家港行、平安银行、青农商行

cmu14-445Fall2020数据库Homework1-SQL

作业1要求编写满足条件的SQL语句 作业要求编写满足条件的SQL语句 作业的地址如下:https://15445.courses.cs.cmu.edu/fall2020/homework1/ 环境配置 实验和环境要求使用的数据库是SQlite,我们用的是Windows所以我们下载SQLite Developer 4.51 下载地址:http://www.sqlitedeveloper.com/sqlite-developer-450-alpha1 下载之后导入从cmu官网下载的数据库文件 musicbra

weixin_44201089的博客 1104

2019-2026年 中国分行业进出口数据 xlsx

数据整理中国各细分行业海关进出口数据,包括中国对各个国家进口、出口数据,中国各个行业进出口数据,各国贸易数据是了解每个国家市场的最基础和重要信息。数据非面板数据,时间、行业分类有缺失。 标 日期 采购商国家/地区 供应商国家/地区 采购商 供应商 采购商地址 供应商地址 通知人 通知人地址 制造商 原产国 目的国 起运港 目的港 HS编码 产品描述 唛头 数量 数量单位 重量 金额($) 单号 集装箱号 品牌

2000-2024年 各地区结婚、离婚、再婚等数据-各地区 xlsx

一般来说,经济发达地区的结婚和离婚率相对较高,而经济欠发达地区的结婚和离婚率相对较低。此外,不同省份的文化、习俗、社会观念等因素也会对结婚和离婚情况产生影响。 本数据从2000年至2024年,对各地区的结婚、离婚及再婚情况进行了全面统计。通过对这些数据的深入分析,我们可以洞察婚姻趋势的演变轨迹,以及地区之间的差异性。这些数据不仅反映了人们的婚姻选择、家庭形态的变化,还揭示了社会动态的演变。对于研究家庭结构和社会变迁的学者而言,这份数据提供了宝贵的参考依据和信息。 相关数据 年份 地区 行政区划代码 所属地域 年末常住人口(万人) 人口出生率(‰) 人口死亡率(‰) 15岁及以上人口数(人口抽样调查)(人) 15岁及以上男性人口数(人口抽样调查)(人) 15岁及以上女性人口数(人口抽样调查)(人) 15岁及以上未婚人口数(人口抽样调查)(人) 15岁及以上男性未婚人口数(人口抽样调查)(人) 15岁及以上女性未婚人口数(人口抽样调查)(人) 15岁及以上初婚有配偶人口数(人口抽样调查)(人) 15岁及以上男性初婚有配偶人口数(人口抽样调查)(人) 15岁及以上女性初婚有配偶人口数(人口抽样调查)(人) 15岁及以上再婚有配偶人口数(人口抽样调查)(人) 15岁及以上男性再婚有配偶人口数(人口抽样调查)(人) 15岁及以上女性再婚有配偶人口数(人口抽样调查)(人) 15岁及以上离婚人口数(人口抽样调查)(人) 15岁及以上男性离婚人口数(人口抽样调查)(人) 15岁及以上女性离婚人口数(人口抽样调查)(人) 15岁及以上丧偶人口数(人口抽样调查)(人) 15岁及以上男性丧偶人口数(人口抽样调查)(人) 15岁及以上女性丧偶人口数(人口抽样调查)(人) 15岁及以上有配偶人口数(人口抽样调查)(人) 15岁及以上男性有配偶人口数(人口抽样调查)(人) 15岁及以上女性有配偶人口数(人口抽样调查)(人) 结婚登记(万对) 内地居民登记结婚(万对) 内地居民初婚登记(万人) 内地居民再婚登记(万人) 涉外及港澳台居民登记结婚(万对) 离婚登记(万对) 粗离婚率(‰)

《CMU15-445/645》fall2018 HOMEWORK #1 - SQL

课程首页

weixin_44520881的博客 1280

后端开发 Docker4.99.0 AppleSilicon 苹果芯片 Mac 安装包

本资源为 Docker Desktop 4.99.0 苹果芯片(Apple Silicon)专用安装包,原生适配 M 系列 Mac,可快速搭建本地容器开发环境,支持镜像拉取、容器编排、项目打包部署。适合后端开发、运维、全栈开发者,用于本地微服务、测试环境、项目容器化开发。

详解B树和B+树的操作原理以及区别

简介 主要针对B树和B+树的插入,删除操作进行解析 注 仅是自己的理解,有不对的地方还请大佬指正 1.B树 1.1.B树的定义 B树也称B-树,它是一颗多路平衡查找树。我们描述一颗B树时需要指定它的阶数,阶数表示了一个结点最多有多少个孩子结点,一般用字母m表示阶数。当m取2时,就是我们常见的二叉搜索树。 1.2:一颗m阶的B树定义如下: 每个节点最多有m-1个关键字 根节点最少可...

LuckFairyLuckBaby的博客 2396

milvus-v2.6.25镜像文件

milvus-v2.6.25镜像文件

医学信息影像AI临床采纳的责任边界研究:基于场景选点与流程嵌入的分步实施路径

内容概要:本文以“影像人工智能(CAD)的临床采纳与责任边界”为核心议题,指出当前影像AI的发展瓶颈已从技术准确性转向“谁负责、怎么用”的机制与治理问题。通过文献研究与政策文本分析,文章系统梳理了CAD的应用场景与效果、临床采纳障碍及责任边界划分三大问题,揭示出“假阳性导致医生信任下降、责任归属不清、采购与使用脱节”三重瓶颈相互强化的闭环结构,并提出“场景选点—试用验证—责任规则先行—流程嵌入”的分步递进式建设路径,强调需通过机制闭环实现技术真正落地。; 适合人群:从事医疗信息化管理、医学人工智能研究、医院运营管理及相关政策制定的专业人员,以及医学信息学、卫生管理专业的高年级本科生与研究生。; 使用场景及目标:①用于医疗机构评估影像AI引入的可行性与实施路径,避免资源错配;②为政策制定者提供优化考核机制与责任界定的理论依据;③帮助AI厂商理解临床真实需求,提升产品与流程的契合度;④作为学术研究框架,支持对技术采纳与治理机制的深入探讨。; 阅读建议:本文构建了“现状—机制—治理”三层分析框架,建议读者结合自身角色聚焦不同章节:管理者重点关注第五章路径设计,研究者关注第三章文献述评与第六章研究展望,实施者关注第四章瓶颈分析与实施保障。阅读时应特别注意概念的操作化定义与证据等级区分,避免将理论推导误作实证结论,并在应用时结合本地实际进行裁剪与验证。

CMU15-445数据库系统课程实验详解

CMU-15-445 学完CMU15-445之后有很大的收获,特别做其中的实验,因此记录了一些笔记。 课程地址 CMU的数据库系统课程时间表 实验代码 课程简介 该课程是CMU的数据库系统的基础课程,实验需要使用C++11,一共有四个实验: 缓冲池管理器 B+树 并发控制 记录和恢复 实验代码在Lab目录下,如果想获得没完成实验前的代码,可以在github搜索,找找就有了。 建议 每次实验前都...

westbrookliu的博客 8828

推动企业技术需求与高校科研成果对接,需要哪些关键支撑要素?.docx

推动企业技术需求与高校科研成果对接,需要哪些关键支撑要素?

国央企创新负责人在推动内部技术转化时,如何确保服务流程的合规与可控?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

A股分钟行情数据,涵盖股票、ETF、可转债及指数 每条记录包含交易日期、具体时间、证券代码、证券简称、开盘价、最高价、最低价、收盘价、成交量、成交额 数据为日内分钟频率,逐分钟记录价格变动与成交信息

A股分钟行情数据,涵盖股票、ETF、可转债及指数。每条记录包含交易日期、具体时间、证券代码、证券简称、开盘价、最高价、最低价、收盘价、成交量、成交额。数据为日内分钟频率,逐分钟记录价格变动与成交信息,按交易日分割存储,历史分钟K线保留完整。 数据源:CMES金融数据库

一个免费的激光打标软件的配套硬件说明

激光打标软件配套硬件说明

国央企在推动创新成果转化时,如何保障技术交易流程的合规性与可追溯性?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

高校技术转移办公室人员如何利用知识图谱技术提升科技成果评价的科学性与高效性?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

上一篇: 15-445 project#0 cpp primer
下一篇: cs144 lab0 networking warmup
RedemptionC
博客等级 码龄11年 103粉丝 84原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值