Posts

Showing posts from September, 2024

Flipkart numbers

 DROP TABLE IF EXISTS SequenceNumbers; CREATE TABLE dbo.SequenceNumbers ( [ID] INT, [Number] INT ) INSERT INTO SequenceNumbers VALUES (1,20),(2,20),(3,20),(4,20),(5,22),(6,24),(7,24),(8,24),(9,20) SELECT * FROM SequenceNumbers

Game of thrones

 DROP TABLE IF EXISTS king; DROP TABLE IF EXISTS battle; CREATE TABLE king (  k_no INT PRIMARY KEY,  king VARCHAR(50),  house VARCHAR(50) ); -- Create the 'battle' table CREATE TABLE battle (  battle_number INT PRIMARY KEY,  name VARCHAR(100),  attacker_king INT,  defender_king INT,  attacker_outcome INT,  region VARCHAR(50)  );   INSERT INTO king (k_no, king, house) VALUES (1, 'Robb Stark', 'House Stark'), (2, 'Joffrey Baratheon', 'House Lannister'), (3, 'Stannis Baratheon', 'House Baratheon'), (4, 'Balon Greyjoy', 'House Greyjoy'), (5, 'Mace Tyrell', 'House Tyrell'), (6, 'Doran Martell', 'House Martell');   INSERT INTO battle (battle_number, name, attacker_king, defender_king, attacker_outcome, region) VALUES (1, 'Battle of Oxcross', 1, 2, 1, 'The North'), (2, 'Battle of Blackwater', 3, 4, 0, 'The North'), (3, 'Battle of the Fords', 1, 5, 1, ...

50 Essential SQL Questions to Land Your Dream Job

 CREATE TABLE worker (     first_name VARCHAR(50),     last_name VARCHAR(50),     department VARCHAR(50),     salary DECIMAL(10, 2),     joining_date DATE ); INSERT INTO worker (first_name, last_name, department, salary, joining_date) VALUES  ('John', 'Doe', 'HR', 55000, '2020-01-15'), ('Jane', 'Smith', 'Finance', 67000, '2019-03-22'), ('Robert', 'Johnson', 'IT', 72000, '2018-06-10'), ('Emily', 'Davis', 'Marketing', 59000, '2021-07-01'), ('Michael', 'Wilson', 'Sales', 63000, '2020-09-15'), ('Sarah', 'Brown', 'HR', 56000, '2022-02-19'), ('David', 'Miller', 'Finance', 68000, '2019-10-05'), ('Laura', 'Garcia', 'IT', 75000, '2020-11-22'), ('James', 'Martinez', 'Marketing', 60000, '2021-03-18'), ('Olivia...

SQL INTERVIEW QUESTION | Hotel Booking Management

 DROP TABLE IF EXISTS Bookings; CREATE TABLE Bookings (     BookingID INT PRIMARY KEY,     BookingDate DATE,     RoomNumber INT ); -- Sample data INSERT INTO Bookings VALUES (1, '2024-01-01', 101), (2, '2024-01-02', 101), (3, '2024-01-04', 101), (4, '2024-01-01', 102), (5, '2024-01-05', 102); SELECT * FROM Bookings

SQL INTERVIEW QUESTION | Work with folders

  drop table if exists workspace; create table workspace (workspaceId int, FolderPath varchar(max)); insert into workspace values (1,'a\b\c') insert into workspace values (1,'a\d') insert into workspace values (1,'a\e') insert into workspace values (1,'a\b\a') insert into workspace values (1,'a\a\a') insert into workspace values (1,'b') insert into workspace values (1,'c') insert into workspace values (1,'c\d\e') insert into workspace values (1,'a\b\c\d') select * from workspace;

rides

 DROP TABLE IF EXISTS rides;  CREATE TABLE rides (     driverid INT,     name VARCHAR(50),     rideid INT PRIMARY KEY,     starttime DATETIME,     endtime DATETIME,     ETA INT,     rating DECIMAL(2, 1) ); INSERT INTO rides (driverid, name, rideid, starttime, endtime, ETA, rating) VALUES (1, 'John', 101, '2024-09-01 08:00:00', '2024-09-01 08:30:00', 35, 4.8), (2, 'Emily', 102, '2024-09-01 09:00:00', '2024-09-01 09:45:00', 50, 4.7), (3, 'David', 103, '2024-09-01 10:00:00', '2024-09-01 10:50:00', 55, 4.5), (4, 'Jessica', 104, '2024-09-01 11:00:00', '2024-09-01 11:30:00', 40, 4.9), (5, 'Michael', 105, '2024-09-01 12:00:00', '2024-09-01 12:25:00', 15, 4.6), (1, 'John', 106, '2024-09-02 08:15:00', '2024-09-02 08:45:00', 40, 4.8), (2, 'Emily', 107, '2024-09-02 09:30:00', '2024-09-02 10:15:00', 50, 4.7), (3, 'David', 10...

Direct/ Indirect employees reporting a manager and direct/ indirect managers of an employee

 DROP TABLE IF EXISTS [employee] CREATE TABLE [employee] ( [ID] int, [Name] varchar(100), [Manager_ID] int ) INSERT INTO [employee] VALUES (1,'Rohit',10), (2,'Rahul',10), (3,'Ravi',10), (4,'Shiva',20), (5,'Sai',20), (6,'Sumit',20), (10,'Priya',100), (11,'Riyaz',100), (12,'Nitin',100), (20,'Yash',100), (22,'Arjun',100), (100,'Naveen',NULL), (50,'Nikhil',1), (60,'Akhil',1) SELECT * FROM employee

ACCENTURE SQL INTERVIEW QUESTION | Change the ProductIDs

 DROP TABLE IF EXISTS Products; CREATE TABLE Products (     ProductID INT PRIMARY KEY,     Product VARCHAR(255),     Category VARCHAR(100) ); INSERT INTO Products (ProductID, Product, Category) VALUES     (1, 'Laptop', 'Electronics'),     (2, 'Smartphone', 'Electronics'),     (3, 'Tablet', 'Electronics'),     (4, 'Headphones', 'Accessories'),     (5, 'Smartwatch', 'Accessories'),     (6, 'Keyboard', 'Accessories'),     (7, 'Mouse', 'Accessories'),     (8, 'Monitor', 'Accessories'),     (9, 'Printer', 'Electronics');

TCS SQL INTERVIEW QUESTION | Categorize Customers Based on Conditions

 DROP TABLE IF EXISTS CustomerPurchases;  CREATE TABLE CustomerPurchases (     CustomerID INT,     DateOfPurchase DATE,     Revenue DECIMAL(10, 2),     ModeOfPurchase VARCHAR(50),     Product VARCHAR(100) ); INSERT INTO CustomerPurchases (CustomerID, DateOfPurchase, Revenue, ModeOfPurchase, Product) VALUES  (1, '2024-03-01', 800.00, 'Online', 'Laptop'), (1, '2024-04-01', 750.00, 'Online', 'Tablet'), (1, '2024-05-01', 1200.00, 'In-Store', 'Smartphone'), (1, '2024-06-01', 900.00, 'Online', 'Television'), (1, '2024-07-01', 1300.00, 'In-Store', 'Gaming Console'), (1, '2024-08-01', 1050.00, 'Online', 'Smartwatch'), (2, '2024-01-15', 1500.00, 'In-Store', 'Refrigerator'), (2, '2024-02-20', 2000.00, 'Online', 'Home Theater System'), (2, '2024-03-25', 1200.00, 'In-Store', 'Washing Machi...