Skip to content

Instantly share code, notes, and snippets.

@AhmedHelalAhmed
Last active April 15, 2021 01:41
Show Gist options
  • Save AhmedHelalAhmed/597e72013eae212f533fd40940de1b0b to your computer and use it in GitHub Desktop.
Save AhmedHelalAhmed/597e72013eae212f533fd40940de1b0b to your computer and use it in GitHub Desktop.
mysql
# https://www.hackerrank.com/challenges/japanese-cities-attributes/submissions
select * from city where countrycode="jpn";
# https://www.hackerrank.com/challenges/japanese-cities-name/problem
select name from city where countrycode = "jpn";
# https://www.hackerrank.com/challenges/revising-the-select-query/problem
select * from CITY where countrycode = "usa" and population >100000
# https://www.hackerrank.com/challenges/revising-the-select-query-2/problem
select name from city where population > 120000 and countrycode = "usa";
# https://www.hackerrank.com/challenges/select-all-sql/problem
select * from city
# https://www.hackerrank.com/challenges/select-by-id/problem
select * from city where id =1661
# https://www.hackerrank.com/challenges/weather-observation-station-1/problem
select city,state from station;
# https://www.hackerrank.com/challenges/weather-observation-station-10/submissions/code/203114632
select distinct (city) from station where
city not like "%e" and
city not like "%a" and
city not like "%i" and
city not like "%o" and
city not like "%u"
# https://www.hackerrank.com/challenges/weather-observation-station-11/problem
select distinct(city)
from station
where
(
city not like "e%" and
city not like "a%" and
city not like "i%" and
city not like "o%" and
city not like "u%"
)
or
(
city not like "%e" and
city not like "%a" and
city not like "%i" and
city not like "%o" and
city not like "%u"
)
# https://www.hackerrank.com/challenges/weather-observation-station-12/problem
select distinct(city)
from station
where
(
city not like "e%" and
city not like "a%" and
city not like "i%" and
city not like "o%" and
city not like "u%"
)
and
(
city not like "%e" and
city not like "%a" and
city not like "%i" and
city not like "%o" and
city not like "%u"
)
# https://www.hackerrank.com/challenges/weather-observation-station-3/problem
select distinct(city) from station where id MOD 2 =0
# https://www.hackerrank.com/challenges/weather-observation-station-4/problem
select count(city) - count(distinct(city)) from station;
# https://www.hackerrank.com/challenges/weather-observation-station-5/problem
select city, LENGTH(city) from station where LENGTH(city) = (SELECT min(count_letters) from (select city, length(city) count_letters from STATION) as data1) order by city limit 1;
select city, LENGTH(city) from station where LENGTH(city) = (SELECT max(count_letters) from (select city, length(city) count_letters from STATION ) as data2) order by city limit 1;
# https://www.hackerrank.com/challenges/weather-observation-station-6/problem
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%"
# https://www.hackerrank.com/challenges/weather-observation-station-7/problem
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"
# https://www.hackerrank.com/challenges/weather-observation-station-8/problem
select distinct(city) from station
where
(
city like "e%" or
city like "a%" or
city like "i%" or
city like "o%" or
city like "u%"
)
and
(
city like "%e" or
city like "%a" or
city like "%i" or
city like "%o" or
city like "%u"
)
# https://www.hackerrank.com/challenges/weather-observation-station-9/problem
select distinct (city) from station where
city not like "e%" and
city not like "a%" and
city not like "i%" and
city not like "o%" and
city not like "u%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment