sqlzoo 8+.Numeric Examples 答案

12 篇文章 0 订阅
本文档详细解析了SQLZoo网站上的NSS教程,涉及如何使用SQL查询特定问题的回答,如计算同意或强烈同意的学生比例,找出不满意的计算机科学学生,比较不同学科的得分等。同时,提供了针对曼彻斯特大学机构的分析,包括加权平均分数和特定专业的学生数量。
摘要由CSDN通过智能技术生成

有什么问题,欢迎评论或私聊。转载请私聊博主,谢谢。

原题链接:https://sqlzoo.net/wiki/NSS_Tutorial

其他题解连接:https://blog.csdn.net/aiqiyizz/article/details/109057732

题解对应的是英文版题目。

8+ Numeric Examples

该数据库来源是一个对成千上万个来自英国高等教育的学生的调查。调查询问了22个问题,学生可以回答STRONGLY DISAGREE, DISAGREE, NEUTRAL, AGREE or STRONGLY AGREE。存储值的形式是用这部分学生占所有学生的PERCENTAGES(百分数)。

table名字叫做nss,保证(机构、科目、问题)组合唯一。

你问我为什么翻译这段?因为不翻译我不知道第一题中的百分数哪来的。。

8+.1 Check out one row

SELECT institution,subject,score,response
  FROM nss
 WHERE question='Q22'
   AND (institution LIKE '%Manchester%')

8+.2 Calculate how many agree or strongly agree

SELECT institution, subject
  FROM nss
 WHERE score >= 100
   AND question = 'Q15'

8+.3 Unhappy Computer Students

SELECT institution,score
  FROM nss
 WHERE question='Q15'
   AND score < 50
   AND subject='(8) Computer Science'

8+.4 More Computing or Creative Students?

需要找题目数据所在行

SELECT subject, SUM(response)
  FROM nss
 WHERE question='Q22'
   AND subject IN ('(8) Computer Science', '(H) Creative Arts and Design')
 GROUP BY subject

8+.5 Strongly Agree Numbers

求人数 百 分 比 × 总 人 数 ÷ 100 ⇒ 百分比\times总人数\div100\Rightarrow ×÷100求和得总人数

正解方式计算出的人数为小数形式,严谨些需要添加ROUND做限制。

SELECT subject, SUM(A_STRONGLY_AGREE*response/100)
  FROM nss
 WHERE question='Q22'
   AND subject IN ('(8) Computer Science', '(H) Creative Arts and Design')
 GROUP BY subject

8+.6 Strongly Agree, Percentage

人 数 百 分 比 = 所 占 人 数 ÷ 总 人 数 × 100 人数百分比=所占人数\div总人数\times100 =÷×100

SELECT subject, ROUND(SUM(A_STRONGLY_AGREE*response/100)/SUM(response)*100)
  FROM nss
 WHERE question='Q22'
   AND subject IN ('(8) Computer Science', '(H) Creative Arts and Design')
 GROUP BY subject

8+.7 Scores for Institutions in Manchester

求的是加权平均数,不能直接用AVG

SELECT institution, ROUND(SUM(score*response)/SUM(response)) AS score
  FROM nss
 WHERE question='Q22'
   AND (institution LIKE '%Manchester%')
 GROUP BY institution

8+.8 Number of Computing Students in Manchester

computing students:计算机专业学生,联想到前面的subject。

使用SUM+CASE WHEN进行计算

SELECT institution, SUM(sample) AS sample, SUM(CASE subject WHEN '(8) Computer Science' THEN sample ELSE 0 END) AS 'computing students'
  FROM nss
 WHERE question='Q01'
   AND (institution LIKE '%Manchester%')
 GROUP BY institution
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VS中无法打开源文件bits/stdc++.h通常是因为该头文件不是标准C++头文件,而是GNU C++编译器的一个扩展头文件。因此,如果你想在VS中使用bits/stdc++.h头文件,你需要手动将该头文件添加到你的项目中。以下是一些步骤: 1. 打开一个文本编辑器,将以下代码复制并粘贴到新文件中: ```cpp #ifndef BITS_STDCPP_H_INCLUDED #define BITS_STDCPP_H_INCLUDED #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <csignal> #include <csetjmp> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <cwchar> #include <cwctype> #include <deque> #include <exception> #include <fstream> #include <functional> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #endif // BITS_STDCPP_H_INCLUDED ``` 2. 将该文件保存为stdc++.h。 3. 将stdc++.h文件复制到你的项目文件夹中。 4. 在VS中打开你的项目,右键单击项目名称,选择“属性”。 5. 在属性窗口中,选择“C/C++” -> “常规”。 6. 在“附加包含目录”字段中添加stdc++.h文件所在的文件夹路径。 7. 点击“应用”和“确定”按钮,保存更改。 现在,你应该能够在VS中使用bits/stdc++.h头文件了。如果你仍然无法使用该头文件,你可以尝试使用其他标准C++头文件来代替它。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值