Code Monkey home page Code Monkey logo

sql-questions-and-notes's Introduction

SQL Practice Repository

Welcome to my SQL practice repository! ๐Ÿ“Š๐Ÿ“š

This repository contains SQL solutions to various questions from LeetCode and HackerRank. It serves as a personal learning resource where I store my solutions and jot down key takeaways and notes as a beginner in SQL.

Contents

  • LeetCode Solutions: SQL solutions to LeetCode questions.
  • HackerRank Solutions: SQL solutions to HackerRank questions.

I hope you find these solutions and notes helpful in your own SQL learning journey. Feel free to explore the content, and if you have any suggestions or improvements, please let me know. Happy coding! ๐Ÿ˜„๐Ÿ“–

SQL Basics and Prerequisites

Before diving into SQL problem-solving on platforms like LeetCode and HackerRank, it's essential to have a good grasp of the basics. This guide provides a quick overview of some fundamental SQL concepts and common query functions: PREREQUISITED.MD)


Now, that you're ready:

LET'S GO!

PROBLEM - 1

https://www.hackerrank.com/challenges/weather-observation-station-6/problem

Solution:

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%';

๐Ÿ’ก I initialy did a mistake in using = sign as in WHERE CITY LIKE = 'a%' But we aren't suppoed to use = with LIKE

PROBLEM - 2

https://www.hackerrank.com/challenges/weather-observation-station-7/problem

Solution:

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' 

Same as above one

PROBLEM - 3

https://www.hackerrank.com/challenges/weather-observation-station-8/problem

Solution:

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 IN (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%' );

A nested variation of two of the above problems

PROBLEM - 4

https://www.hackerrank.com/challenges/weather-observation-station-9/problem

Solution:

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 IN (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%' );

PROBLEM - 5

https://www.hackerrank.com/challenges/more-than-75-marks/problem

Solution:

SELECT NAME 
FROM STUDENTS
WHERE MARKS>75 
ORDER BY RIGHT(NAME,3), ID ASC;

There are a lot of takeaways in this problem. Firstly you get to know about using a secondary order and right string function also. Here is more about it. In SQL, RIGHT() is a string function that is used to extract a specified number of characters from the right end (end of the string) of a given string. The syntax for the RIGHT() function is as follows:

RIGHT(string_expression, number_of_characters)
  • string_expression: This is the input string from which you want to extract characters. - number_of_characters: This is an integer value that specifies how many characters you want to extract from the right end of the input string.

Here's an example of how to use the RIGHT() function:

SELECT RIGHT('Hello, World!', 6); -- This returns 'World!'

PROBLEM - 5

https://www.hackerrank.com/challenges/name-of-employees/problem

Solution:

SELECT NAME 
FROM EMPLOYEE
ORDER BY NAME;

It's written as OREDER BY and not OREDERBY :)

sql-questions-and-notes's People

Contributors

ayushichoudhary-19 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.