HackerRank第一趴-[亲测有效]

HackerRank第一趴-[亲测有效]CITY表: Field Type ID number NAME VARCHAR2(17) COUNTRYCODE VARCHAR2(3) DISTRICT VARCHAR2(20) POPULATI

HackerRank第一趴-

CITY表:

Field Type
ID number
NAME VARCHAR2(17)
COUNTRYCODE VARCHAR2(3)
DISTRICT VARCHAR2(20)
POPULATION number

 

1、Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA.

select * from CITY
where POPULATION>=100000 and COUNTRYCODE="USA";

 

2、Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.

select Name from CITY
where COUNTRYCODE ="USA" and POPULATION>=120000;

3、Query all columns (attributes) for every row in the CITY table.

select * from CITY;

 4、Query all columns for a city in CITY with the ID 1661.

select * from CITY
where ID =1661;

 

5、Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is JPN.

select * from CITY
where COUNTRYCODE="JPN";

6、Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.

select NAME
from CITY
where COUNTRYCODE="JPN"

 

STATION表:

Field Type
ID number
CITY VARCHAR2(21)
STATE VARCHAR2(2)
LAT_N number
LONG_W number

1、Query a list of CITY and STATE from the STATION table.

select CITY,STATE
from STATION;

2、Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.

从 STATION 查询具有偶数 ID 号的城市的 CITY 名称列表。 以任意顺序打印结果,但从答案中排除重复项。

select DISTINCT(CITY)
from STATION
where mod(ID,2)=0;

3、Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.

求表中 CITY 条目总数与表中不同 CITY 条目数之间的差值。

select COUNT(CITY)-COUNT(DISTINCT(CITY))
from STATION;

4、Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.

用最短和最长的 CITY 名称查询 STATION 中的两个城市,以及它们各自的长度(即:名称中的字符数)。 如果有多个最小或最大的城市,请选择按字母顺序排列的第一个城市。

方法1: where子句+limit

select CITY,length(CITY) from STATION
where length(CITY)>=ALL(select length(CITY) from STATION) or length(CITY)<=ALL(select length(CITY) from STATION)
order by 2 desc,1
limit 2;

解题思路:

方法2:union+limit

(select CITY,length(CITY) from STATION
order by 2 desc,1 desc
limit 1)
union
(select CITY,length(CITY) from STATION
order by 2,1
limit 1);

解题思路:两个表组合。

5、Query the list of CITY names starting with vowels (i.e., aeio, or u) from STATION. Your result cannot contain duplicates.

从 STATION 查询以元音开头的 CITY 名称列表(即 a、e、i、o 或 u)。 您的结果不能包含重复项。

select DISTINCT(CITY)
from STATION
where CITY LIKE"a%" or CITY LIKE"e%" or CITY LIKE"i%" or CITY LIKE"o%" or CITY LIKE"u%";

6、Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates.

从 STATION 查询以元音结尾的 CITY 名称列表(即 a、e、i、o 或 u)。 您的结果不能包含重复项。

 

select DISTINCT(CITY)
from STATION
where CITY LIKE "%a" or CITY LIKE "%e" or CITY LIKE "%i" or CITY LIKE "%o" or CITY LIKE "%u";

7、Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.

从 STATION 查询以元音开头和结尾的 CITY 名称列表(即 a、e、i、o 或 u)。 您的结果不能包含重复项。

select DISTINCT(CITY)
from STATION
where (CITY LIKE "%a" or CITY LIKE "%e" or CITY LIKE "%i" or CITY LIKE "%o" or CITY LIKE "%u") and (CITY LIKE"a%" or CITY LIKE"e%" or CITY LIKE"i%" or CITY LIKE"o%" or CITY LIKE"u%");

8、Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates.

从 STATION 查询不能以元音开头的 CITY 名称列表(即 a、e、i、o 或 u)。 您的结果不能包含重复项。

select DISTINCT(CITY)
from STATION
where CITY NOT LIKE "a%" and CITY NOT LIKE "e%" and CITY NOT LIKE "i%" and CITY NOT LIKE "o%" and CITY NOT LIKE "u%";

9、Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates.

从 STATION 查询不能以元音结尾的 CITY 名称列表(即 a、e、i、o 或 u)。 您的结果不能包含重复项。

select DISTINCT(CITY)
from STATION
where CITY NOT LIKE "%a" and CITY NOT LIKE "%e" and CITY NOT LIKE "%i" and CITY NOT LIKE "%o" and CITY NOT LIKE "%u";

10、Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates.

从 STATION 查询不以元音开头或不以元音结尾的 CITY 名称列表。 您的结果不能包含重复项。

select DISTINCT(CITY)
from STATION
where (CITY NOT LIKE "a%" and CITY NOT LIKE "e%" and CITY NOT LIKE "i%" and CITY NOT LIKE "o%" and CITY NOT LIKE "u%") or (CITY NOT LIKE "%a" and CITY NOT LIKE "%e" and CITY NOT LIKE "%i" and CITY NOT LIKE "%o" and CITY NOT LIKE "%u");

11、Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates.

从 STATION 查询不以元音开头和不以元音结尾的 CITY 名称列表。 您的结果不能包含重复项。

select DISTINCT(CITY)
from STATION
where (CITY NOT LIKE "a%" and CITY NOT LIKE "e%" and CITY NOT LIKE "i%" and CITY NOT LIKE "o%" and CITY NOT LIKE "u%") and (CITY NOT LIKE "%a" and CITY NOT LIKE "%e" and CITY NOT LIKE "%i" and CITY NOT LIKE "%o" and CITY NOT LIKE "%u");

 

STUDENTS表:

Field Type
ID INTEGER
Name String
Maks INTEGER

1、Query the Name of any student in STUDENTS who scored higher than  Marks. Order your output by the last three characters of each name. If two or more students both have names ending in the same last three characters (i.e.: Bobby, Robby, etc.), secondary sort them by ascending ID.

查询 STUDENTS 中任何得分高于 75 的学生的姓名。 按每个名称的最后三个字符对输出进行排序。 如果两个或多个学生的名字都以相同的最后三个字符结尾(即:Bobby、Robby 等),则按 ID 升序对他们进行二次排序。

select Name from STUDENTS
where Marks>75
order by right(Name,3),ID;

解题思路,按照每个名字的最后三个字符排序,order by 和right函数结合使用。

 

Employee表:

Field Type
employee_id INTEGER
name String
months INTEGER
salary INTEGER

 

1、Write a query that prints a list of employee names (i.e.: the name attribute) from the Employee table in alphabetical order.

select name 
from Employee
order by name;

2、

Write a query that prints a list of employee names (i.e.: the name attribute) for employees in Employee having a salary greater than  per month who have been employees for less than  months. Sort your result by ascending employee_id.

编写一个查询,打印员工姓名列表(即:名称属性),用于 Employee 中薪水大于每月且工作时间少于几个月的员工。 按employee_id 升序对结果进行排序。

select name
from Employee
where salary>2000 and months<10
order by employee_id;

 

原文地址:https://www.cnblogs.com/ruoli-121288/archive/2022/06/02/16335207.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/5169.html

(0)
上一篇 2023-05-20 12:30
下一篇 2023-05-20

相关推荐

  • Python教程示例:动手学习

    Python教程示例:动手学习Python是一种易于学习的编程语言。以下是Python的几个基本语法示例。

    2024-03-15
    77
  • Python Dictionary:快速查找数值和对应数据

    Python Dictionary:快速查找数值和对应数据a href=”https://beian.miit.gov.cn/”苏ICP备2023018380号-1/a Copyright www.python100.com .Some Rights Reserved.

    2024-03-22
    74
  • MySQL版本引起的错误

    MySQL版本引起的错误各位看官可以关注博主个人博客,了解更多信息。 作者:Surpasser 链接地址:https://surpass.org.cn 前言 接上一篇帖子,博主在CentOS上安装了最新版的MySQL容器(版

    2023-04-15
    149
  • ORACLE重编译同义词(synonym)遇到ORA-01031总结

    ORACLE重编译同义词(synonym)遇到ORA-01031总结我们在编译INVALID的同义词(synonym)的时候,可能在某些版本会遇到一些特殊权限问题,具体来说是遇到ORA-01031错误。下面构造这样一个例子: 如下所示,scott用户下面创建了一个公共

    2023-04-18
    152
  • 使用jsreplace方法替换文本内容

    使用jsreplace方法替换文本内容在开发网站和应用程序时,经常需要对文本内容进行替换操作。有时候,我们需要替换特定的单词或短语,有时候需要替换大段的文本。使用JavaScript的replace方法可以帮助我们轻松实现这一功能。

    2024-08-09
    28
  • mysql 性能调优_MySQL数据库优化

    mysql 性能调优_MySQL数据库优化EXPLAIN 首先祭出官方文档(这是5.7的,请自行选择版本): Understanding the Query Execution Plan 英文不想看,就看这篇吧: 全网最全 | MySQL E

    2023-05-16
    159
  • 无效的Python SDK

    无效的Python SDKPython是一门高级编程语言,其简单易用、灵活多变的特点受到了众多开发者的喜爱。在Python生态圈中,开发者可以便捷地使用各种SDK开发自己的应用。但是,尽管Python的生态圈已经相当成熟和完善,仍然有一些Python SDK存在问题。本文主要讨论无效的Python SDK,这类SDK通常存在着质量不佳、未经充分测试、文档不完整等问题,使它们在生产环境中难以使用。

    2024-07-31
    39
  • Python中将元组转换为列表的方法

    Python中将元组转换为列表的方法Python中元组(tuple)和列表(list)是两种具有不同性质的序列类型。在某些情况下,需要将元组转换为列表,因为列表在某些操作中具有更好的可变性和处理性能。本文将详细介绍Python中将元组转换为列表的方法,包括使用列表解析、使用typecasting、使用extend方法、使用list构造函数以及使用循环遍历等方法。

    2024-03-26
    89

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注