M

@mukulg712

fill missing data

SQL
17 hours ago
-- 1. Create the products table CREATE TABLE products ( product_id INT PRIMARY KEY, category VARCHAR(50), name VARCHAR(50) ); -- 2. Insert the sample data (with missing category fields) INSERT INTO products (product_id, category, name)

flight routes

MySQL
10 months ago
CREATE TABLE airports ( port_code VARCHAR(10) PRIMARY KEY, city_name VARCHAR(100) ); CREATE TABLE flights ( flight_id varchar (10), start_port VARCHAR(10), end_port VARCHAR(10), start_time datetime,

create a team of 3 people, preserve the order of names as in table and if not 3 members group

MySQL
10 months ago
-- Create the table CREATE TABLE emp_details ( emp_name VARCHAR(10), city VARCHAR(15) ); -- Insert sample data INSERT INTO emp_details (emp_name, city) VALUES ('Sam', 'New York'), ('David', 'New York'),

ab testing users performing better

SQL
11 months ago
CREATE TABLE ab_test ( user_id INT, variant CHAR(1), converted TINYINT ); INSERT INTO ab_test (user_id, variant, converted) VALUES (1, 'A', 1), (2, 'A', 0), (3, 'A', 1), (4, 'A', 0),

Sandwich Pattern

SQL
11 months ago
CREATE TABLE NUM ( SN INT, NUMB INT ); -- Step 2: Insert sample data INSERT INTO NUM (SN, NUMB) VALUES (1, 4), (2, 7), (3, 4),

Match Combinations

SQL
11 months ago
-- Create the table CREATE TABLE teams ( team_name VARCHAR(50) NOT NULL ); -- Insert team names INSERT INTO teams (team_name) VALUES ('CSK'), ('KKR'), ('GT'),

icc_world_cup tournament

SQL
11 months ago
create table icc_world_cup ( Team_1 Varchar(20), Team_2 Varchar(20), Winner Varchar(20) ); INSERT INTO icc_world_cup values('India','SL','India'); INSERT INTO icc_world_cup values('SL','Aus','Aus'); INSERT INTO icc_world_cup values('SA','Eng','Eng')

Employee present and absent

SQL
1 year ago
create table emp_attendance ( employee varchar(10), dates date, status varchar(20) ); insert into emp_attendance values('A1', '2024-01-01', 'PRESENT'); insert into emp_attendance values('A1', '2024-01-02', 'PRESENT'); insert into emp_attenda

lift weight problem

SQL
1 year ago
create table lifts ( id int , capacity_kg int ); insert into lifts values (1, 300); insert into lifts values (2, 350); create table lift_passengers

pivot and unpivot

MySQL
1 year ago
-- create a table CREATE TABLE TBL ( prodID NVARCHAR(6), fieldName NVARCHAR(20), fieldValue NVARCHAR(20) ); -- insert some values INSERT INTO TBL (prodId, fieldName, fieldValue) VALUES ('ABC123', 'name' , 'widget1'), ('ABC123', 'descript

Regex Code 3

Python
2 years ago
import re text = 'Hi, How are you?' #PATTERN = re.compile(r'\d{2}[-\./]([a-zA-Z]{3}|\d{2})[-\./]\d{4}') #date pattern #PATTERN = re.compile(r'\w+@[a-z]+(\.[a-z]{2,3})+') #email pattern #PATTERN = re.compile(r'(\+\d)?\d{3}[-\.]\d{3}\s?\d{4}') #phon

Regex Code 2

Python
2 years ago
import re text = '''Hi, today is 17-Apr-2021, yesterday was 16-Apr-2021 and tomorrow will be 18-Apr-2021. My schedule is free on 26-04-2021, 06.05.2021 and 16/Jun/2021. You can reach out to me at myname2020@dummy.com or ask_help@demo.net & confere

Regex Code

Python
2 years ago
import re text = 'ABC 123 xYZ 456 @$! 100' PATTERN = re.compile(r'\d\d\d') #matches = PATTERN.search(text) #searches 1st instance of the match matches = PATTERN.finditer(text) #iteratively matches every instance of the match for i in matches:

Fill the NULL values in the column with last value

MySQL
2 years ago
create table brands ( category varchar(20), brand_name varchar(20) ); insert into brands values ('chocolates','5-star') ,(null,'dairy milk') ,(null,'perk') ,(null,'eclair')

Finding working days SQL

MySQL
2 years ago
create table tickets ( ticket_id varchar(10), create_date date, resolved_date date ); delete from tickets; insert into tickets values (1,'2022-08-01','2022-08-03') ,(2,'2022-08-01','2022-08-12')

Recursive CTE total sales per year by Product

MySQL
2 years ago
create table sales ( product_id int, period_start date, period_end date, average_daily_sales int ); insert into sales values(1,'2019-01-25','2019-02-28',100),(2,'2018-12-01','2020-01-01',10),(3,'2019-12-01','2020-01-31',1);

Udaan Year wise count of New City

MySQL
2 years ago
create table business_city ( business_date date, city_id int ); delete from business_city; insert into business_city values(cast('2020-01-02' as date),3),(cast('2020-07-01' as date),7),(cast('2021-01-01' as date),3),(cast('2021-02-03' as date),19) ,

products in customer budget

MySQL
2 years ago
create table products ( product_id varchar(20) , cost int ); insert into products values ('P1',200),('P2',300),('P3',500),('P4',800); create table customer_budget ( customer_id int,

4 consecutive seats in a theatre

SQL
2 years ago
create table movie( seat varchar(50),occupancy int ); insert into movie values('a1',1),('a2',1),('a3',0),('a4',0),('a5',0),('a6',0),('a7',1),('a8',1),('a9',0),('a10',0), ('b1',0),('b2',0),('b3',0),('b4',1),('b5',1),('b6',1),('b7',1),('b8',0),('b9',0