{"id":13603483,"url":"https://github.com/Imran53/SQL-Mastery-for-Interviews","last_synced_at":"2025-04-11T19:32:05.588Z","repository":{"id":189820052,"uuid":"572971702","full_name":"Imran53/SQL-Mastery-for-Interviews","owner":"Imran53","description":"Level up your SQL skills for interviews! Explore a curated collection of SQL resources, interview questions, answers, PDFs, YouTube channels, websites, and Hackerrank solutions. Get ready to excel in SQL-related interviews with comprehensive learning materials and real-world problem-solving examples.","archived":false,"fork":false,"pushed_at":"2023-11-11T14:13:05.000Z","size":1825,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-07T07:46:43.083Z","etag":null,"topics":["hackerrank-solutions","hackerrank-sql","interview-preparation","interview-questions","sql","sql-query"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Imran53.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-01T12:31:42.000Z","updated_at":"2024-03-05T08:08:46.000Z","dependencies_parsed_at":"2023-08-21T22:59:22.918Z","dependency_job_id":"51c5b4be-9be5-4b5f-a0a4-7004ac3a4427","html_url":"https://github.com/Imran53/SQL-Mastery-for-Interviews","commit_stats":null,"previous_names":["imran53/sql-mastery-for-interviews"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran53%2FSQL-Mastery-for-Interviews","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran53%2FSQL-Mastery-for-Interviews/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran53%2FSQL-Mastery-for-Interviews/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Imran53%2FSQL-Mastery-for-Interviews/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Imran53","download_url":"https://codeload.github.com/Imran53/SQL-Mastery-for-Interviews/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248466985,"owners_count":21108576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hackerrank-solutions","hackerrank-sql","interview-preparation","interview-questions","sql","sql-query"],"created_at":"2024-08-01T19:00:23.240Z","updated_at":"2025-04-11T19:32:05.181Z","avatar_url":"https://github.com/Imran53.png","language":null,"funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Important_SQL\n\n**Revising the Select Query I**\n\nProblem Link: https://www.hackerrank.com/challenges/revising-the-select-query/problem?isFullScreen=true\n```javascript\nselect *\nfrom city\nwhere population\u003e100000 and countrycode=\"USA\";\n```\n\n**Revising the Select Query II**\n\nProblem Link: https://www.hackerrank.com/challenges/revising-the-select-query-2/problem?isFullScreen=true\n```\nselect name from city where population\u003e120000 and countrycode=\"usa\";\n```\n\n**Select All**\n\nProblem Link: https://www.hackerrank.com/challenges/select-all-sql/problem?isFullScreen=true\n```\nselect * from city;\n```\n\n**Select By ID**\n\nProblem Link: https://www.hackerrank.com/challenges/select-by-id/problem?isFullScreen=true\n```\nselect * from city where id=1661;\n```\n\n\n**Japanese Cities' Attributes**\n\nProblem Link: https://www.hackerrank.com/challenges/japanese-cities-attributes/problem?isFullScreen=true\n```\nSelect *\nfrom city\nwhere countrycode=\"jpn\";\n```\n\n**Japanese Cities' Names**\n\nProblem Link: https://www.hackerrank.com/challenges/japanese-cities-name/problem?isFullScreen=true\n```\nselect name\nfrom city\nwhere countrycode=\"jpn\";\n```\n\n**Weather Observation Station 1**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-1/problem?isFullScreen=true\n```\nselect city,state from station;\n```\n\n\n**Weather Observation Station 3**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-3/problem?isFullScreen=true\n```\nselect distinct city from station where id%2=0\n```\n\n**Weather Observation Station 4**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-4/problem?isFullScreen=true\n\n```\nselect count(city)-count(distinct city) from station;\n```\n\n**Weather Observation Station 5**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-5/problem?isFullScreen=true\n```\nselect city, length(city) from station order by length(city), city limit 1;\nselect city, length(city) from station order by length(city)desc, city limit 1;\n```\n\n**Weather Observation Station 6**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-6/problem?isFullScreen=true\n```\nselect distinct(city) from station where\ncity like \"a%\" or\ncity like \"e%\" or\ncity like \"i%\" or\ncity like \"o%\" or\ncity like \"u%\";\n```\n\n**Weather Observation Station 7**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-7/problem?isFullScreen=true\n```\nselect distinct(city) from station where\ncity like \"%a\" or\ncity like \"%e\" or\ncity like \"%i\" or\ncity like \"%o\" or\ncity like \"%u\";\n```\n\n**Weather Observation Station 8**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-8/problem?isFullScreen=true\n\n```\nselect distinct city from station where\n(city like \"a%\" or city like \"e%\" or city like \"i%\" or city like \"o%\" or city like \"u%\")\nand\n(city like \"%a\" or city like \"%e\" or city like \"%i\" or city like \"%o\" or city like \"%u\");\n```\n\n**Weather Observation Station 9**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-9/problem?isFullScreen=true\n```\nselect distinct city from station where\ncity not like \"a%\" and\ncity not like \"e%\" and\ncity not like \"i%\" and\ncity not like \"o%\" and\ncity not like \"u%\";\n```\n\n**Weather Observation Station 10**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-10/problem?isFullScreen=true\n```\nselect distinct city from station where\ncity not like \"%a\" and\ncity not like \"%e\" and\ncity not like \"%i\" and\ncity not like \"%o\" and\ncity not like \"%u\";\n```\n\n**Weather Observation Station 11**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-11/problem?isFullScreen=true\n```\nselect 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');\n```\n\n**Weather Observation Station 12**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-12/problem?isFullScreen=true\n```\nselect 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');\n```\n**Higher Than 75 Marks**\n\nProblem Link: https://www.hackerrank.com/challenges/more-than-75-marks/problem?isFullScreen=true\n```\nselect name from students where marks\u003e75 order by right(name,3),id;\n```\n\n**Employee Names**\n\nProblem Link: https://www.hackerrank.com/challenges/name-of-employees/problem?isFullScreen=true\n\n```\nselect name from employee order by name;\n```\n\n**Employee Salaries**\n\nProblem Link: https://www.hackerrank.com/challenges/salary-of-employees/problem?isFullScreen=true\n```\nselect name from employee where salary\u003e2000 and months\u003c10 order by employee_id;\n```\n\n**Revising Aggregations - The Count Function**\n\nProblem Link: https://www.hackerrank.com/challenges/revising-aggregations-the-count-function/problem?isFullScreen=true\n```\nselect count(*) from city where population\u003e100000;\n```\n\n**Revising Aggregations - The Sum Function**\n\nProblem Link: https://www.hackerrank.com/challenges/revising-aggregations-sum?isFullScreen=true\n```\nselect sum(population) from city where district=\"California\";\n```\n\n**Revising Aggregations - Averages**\n\nProblem Link: https://www.hackerrank.com/challenges/revising-aggregations-the-average-function?isFullScreen=true\n```\nselect avg(population) from city where district=\"california\";\n```\n\n**Average Population**\n\nProblem Link: https://www.hackerrank.com/challenges/average-population?isFullScreen=true\n```\nselect floor(avg(population)) from city;\n```\n\n**Japan Population**\n\nProblem Link: https://www.hackerrank.com/challenges/japan-population?isFullScreen=true\n```\nselect sum(population) from city where countrycode=\"jpn\";\n```\n\n**Population Density Difference**\n\nProblem Link: https://www.hackerrank.com/challenges/population-density-difference?isFullScreen=true\n```\nselect max(population)-min(population) from city;\n```\n\n**The Blunder**\n\nProblem Link: https://www.hackerrank.com/challenges/the-blunder?isFullScreen=true\n```\nselect ceil(avg(salary)-avg(replace(salary,0,''))) from employees;\n```\n\n**Top Earners**\n\nProblem Link: https://www.hackerrank.com/challenges/earnings-of-employees?isFullScreen=true\n```\nselect salary*months as earnings, count(*)\nfrom employee\ngroup by earnings\norder by earnings desc\nlimit 1;\n```\n\n**Weather Observation Station 2**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-2?isFullScreen=true\n```\nselect round(sum(lat_n),2),round(sum(long_w),2)\nfrom station;\n```\n\n**Weather Observation Station 13**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-13?isFullScreen=true\n```\nselect round(sum(lat_n),4) from station\nwhere lat_n\u003e38.7880 and lat_n\u003c137.2345;\n```\n\n**Weather Observation Station 14**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-14?isFullScreen=true\n```\nselect round(max(lat_n),4)\nfrom station\nwhere lat_n\u003c137.2345;\n```\n\n**Weather Observation Station 15**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-15?isFullScreen=true\n```\nselect round(long_w,4)\nfrom station\nwhere lat_n=(select max(lat_n) from station where lat_n\u003c137.2345);\n```\n\n**Weather Observation Station 16**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-16?isFullScreen=true\n```\nselect round(min(lat_n),4) from station where lat_n\u003e38.7780;\n```\n\n**Weather Observation Station 17**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-17?isFullScreen=true\n```\nselect round(long_w,4) from station where lat_n= (select min(lat_n) from station where lat_n\u003e38.7780);\n```\n\n**Weather Observation Station 18**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-18?isFullScreen=true\n```\nselect round(abs(min(lat_n)-max(lat_n))+abs(min(long_w)-max(long_w)),4) from station;\n```\n\n**Weather Observation Station 19**\n\nProblem Link: https://www.hackerrank.com/challenges/weather-observation-station-19?isFullScreen=true\n```\nselect round(sqrt(power(max(lat_n)-min(lat_n),2)+power(max(long_w)-min(long_w),2)),4) from station;\n```\n\n**Population Census**\n\nProblem Link: https://www.hackerrank.com/challenges/asian-population?isFullScreen=true\n```\nselect sum(city.population)\nfrom city, country\nwhere city.countrycode = country.code and country.continent= 'asia';\n```\n\n**African Cities**\n\nProblem Link: https://www.hackerrank.com/challenges/african-cities?isFullScreen=true\n```\nselect city.name from city,country where city.countrycode = country.code and country.continent='Africa';\n```\n\n**Average Population of Each Continent**\n\nProblem Link: https://www.hackerrank.com/challenges/average-population-of-each-continent?isFullScreen=true\n```\nSELECT Country.Continent, FLOOR(AVG(City.Population))\nFROM Country, City \nWHERE Country.Code = City.CountryCode \nGROUP BY Country.Continent ;\n```\n\n**Department Highest Salary**\n\nProblem Link: https://leetcode.com/problems/department-highest-salary/\n```\nselect d.name as department,e.name as employee, e.salary \nfrom department d, employee e\nwhere e.departmentid=d.id\nand e.salary=(select max(salary) from employee e1 \n             where e1.departmentid=d.id);\n```\n\n**Department Top Three Salaries**\n\nProblem Link: https://leetcode.com/problems/department-top-three-salaries/\n```\nselect d.name as Department, e1.name as Employee, e1.salary as Salary\n    From Employee as e1  join Department as d\n    on e1.departmentId = d.id\n    where 3 \u003e (Select count(distinct(e2.salary)) \n            from Employee as e2\n            where e2.salary\u003ee1.salary\n            and e1.departmentId = e2.departmentId);\n```\n\n**Second Highest Salary**\n\nProblem Link: https://leetcode.com/problems/second-highest-salary/\n```\nSELECT MAX(salary) as SecondHighestSalary\nFROM Employee\nWHERE salary \u003c (SELECT MAX(salary) FROM Employee);\n```\n\n**Dept wise highest salary**\n```\nSelect max(salary), deptNo \nFrom emp \nGroup by deptNo;\n```\n\n\n**Salary decreasing order**\n```\nSelect salary from emp order by salary desc;\n```\n\n**2nd highest salary**\n```\nSelect max(Salary) from emp where salary \u003c(select max(salary) from emp);\n```\n\n**Top 3 highest salary**\n```\nSelect * from(select distinct salary from emp order by salary desc) where rownum\u003c=3;\n```\n\n**3rd highest salary**\n\n```\nSelect * from(select distinct salary from emp order by salary desc) where rownum\u003c=3\nMinus\nSelect * from(select distinct salary from emp order by salary desc) where rownum\u003c=2;\n```\n\n\n**SQL Aliases**\n\n_SQL aliases are used to give a table, or a column in a table, a temporary name._\nAliases are often used to make column names more readable.\n```\nSelect customerName as customer, customerId as id\nFrom customerTable;\n```\n\n**SQL FULL OUTER JOIN**\n\n_The FULL OUTER JOIN keyword returns all matching records from both tables whether the other table matches or not. So, if there are rows in \"Customers\" that do not have matches in \"Orders\", or if there are rows in \"Orders\" that do not have matches in \"Customers\", those rows will be listed as well._\n```\nSELECT Customers.CustomerName, Orders.OrderID\nFROM Customers\nFULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID\nORDER BY Customers.CustomerName;\n```\n\nlink : https://www.w3schools.com/sql/sql_join_full.asp\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FImran53%2FSQL-Mastery-for-Interviews","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FImran53%2FSQL-Mastery-for-Interviews","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FImran53%2FSQL-Mastery-for-Interviews/lists"}