SELECT *
FROM (
SELECT Year, Quarter, Sales
FROM SalesData
) AS SourceTable
PIVOT (
SUM(Sales) FOR Quarter IN (Q1, Q2, Q3, Q4)
) AS PivotTable;
SELECT
Year,
SUM(CASE WHEN Quarter = 'Q1' THEN Sales ELSE 0 END) AS Q1,
SUM(CASE WHEN Quarter = 'Q2' THEN Sales ELSE 0 END) AS Q2,
SUM(CASE WHEN Quarter = 'Q3' THEN Sales ELSE 0 END) AS Q3,
SUM(CASE WHEN Quarter = 'Q4' THEN Sales ELSE 0 END) AS Q4
FROM SalesData
GROUP BY Year;
SELECT Year, Quarter, Sales
FROM (
SELECT Year, Q1, Q2, Q3, Q4
FROM SalesData
) AS SourceTable
UNPIVOT (
Sales FOR Quarter IN (Q1, Q2, Q3, Q4)
) AS UnpivotedTable;
SELECT Year, 'Q1' AS Quarter, Q1 AS Sales FROM SalesData
UNION ALL
SELECT Year, 'Q2' AS Quarter, Q2 AS Sales FROM SalesData
UNION ALL
SELECT Year, 'Q3' AS Quarter, Q3 AS Sales FROM SalesData
UNION ALL
SELECT Year, 'Q4' AS Quarter, Q4 AS Sales FROM SalesData;
DELIMITER $$
CREATE TRIGGER before_salary_update
BEFORE UPDATE ON employees
FOR EACH ROW
BEGIN
-- Check if the salary has actually changed
IF [Link] <> [Link] THEN
INSERT INTO salary_history (employee_id, old_salary, new_salary, change_date)
VALUES (OLD.employee_id, [Link], [Link], CURRENT_TIMESTAMP);
END IF;
END $$
DELIMITER ;
UPDATE employees
SET salary = 55000.00
WHERE employee_id = 1;
a trigger is a special kind of stored procedure that automatically executes or fires when specific events occur on a table or view
DELIMITER $$
CREATE FUNCTION get_elite_status_description(status INT)
RETURNS VARCHAR(50)
DETERMINISTIC
BEGIN
DECLARE status_description VARCHAR(50);
-- Logic to map status value to status description
IF status = 0 THEN
SET status_description = 'General';
ELSEIF status = 1 THEN
SET status_description = 'Silver';
ELSEIF status = 2 THEN
SET status_description = 'Gold';
ELSEIF status = 3 THEN
SET status_description = 'Platinum';
ELSEIF status = 4 THEN
SET status_description = '1K';
ELSEIF status = 5 THEN
SET status_description = 'GS'; -- Grand Slam
ELSE
SET status_description = 'Unknown'; -- For any invalid status
END IF;
-- Return the description
RETURN status_description;
END $$
DELIMITER ;
A stored function in SQL (also known as a user-defined function or UDF) is a stored program that you can use to perform oper
can use to perform operations and return a single value.
Over the years, I’ve learned that my professional satisfaction comes from being in a role where I can contribute meaningfull
continue developing my skills, and feel part of a supportive team. I’ve carefully considered this opportunity, and I believe th
my skills and long-term aspirations. I’m looking for a place where I can build a lasting career, and I see that here with your c
At this stage in my career, I’m looking for stability and a place where I can truly invest myself. I’ve had experiences where I’ve
with my long-term goals, but I’m very careful about choosing the right fit for my skills and aspirations
I’m excited about this opportunity because it feels like a place where I can settle in, continue learning, and build a lasting caree
Why have you changed your job so frequently:
I know I have changed jobs a few times but each move was to enhance my skill set and to take on new chllanges and grow [pr
At each step I was lookinf ofr a job that alligns with myy lonng term goals and I believe these experiemce has prepared me to c
Why should we hire you:
You should hire me for my passion for problem solving and critical thinking.
I bring 5 years of data analytics experice in converting data into actionable insights.
I have the required skill set and experience that will be needed for this job and apart from that
I also have experience in sharing and communicating insights with non technical stakeholders as well either in form of PPT or i
in addition to my technical skills I also bring good communication skills and colleborative skills as well. I have previously colebo
s for this as well.
What motivates you to do a good job.
self motivated person.
I am also motivated by the oppourtinuity to make a real impact it can be anything llike helping team in meeting goals or contri
Knowing that my efforts has a direct effect on the outcome really drive me to do a great job/
Greatest strength
I would say my greatest strength is my strong work ethic. I take pride in being reliable, consistent, and dedicated to achieving
I believe in giving my best effort in everything I do, whether it’s a small task or a large project. I’m very results-driven,
and I always strive to ensure that my work not only meets expectations but exceeds them when possible.
Weakness
"One of my weaknesses has been that I tend to take on a lot of responsibility myself and don’t always ask for help as quickly a
and I sometimes feel that I should be able to solve problems or complete tasks on my own. In my previous role, this tendency
was reluctant to ask for help, thinking I could manage it all. As a result, there were a few instances where I faced challenges in
Expectations from this job:
I expect this job to challenge me and help me grow professionally.
I am excited about the possibility of tackling new and comples challlanges that will help me expending my skillset and my know
I also expect to work in an environment in which contributins are appriciated and celebrated and a positive and supportive en
Where do you see your self in 5 years:
I see myself having grown into more senior role where I can contribute on a heigher level.
I am also excited about the kind of work that the organisation do and I would love to be a part of that growth story as well.
as I am in ever changing field of analysis and data I also aim to expand my skill set and become a expert of my filed or became
DELIMITER $$ -- Change the delimiter to $$ to allow semicolons in the body of the procedure
CREATE PROCEDURE GetEmployeesByDeptAndSalaryRange (
IN dept_name VARCHAR(100), -- Department name to filter employees
IN min_salary DECIMAL(10, 2), -- Minimum salary to filter employees
IN max_salary DECIMAL(10, 2) -- Maximum salary to filter employees
)
BEGIN
-- SQL query to fetch employees based on department and salary range
SELECT employee_id, first_name, last_name, department, salary
FROM employees
WHERE department = dept_name
AND salary BETWEEN min_salary AND max_salary;
END $$
DELIMITER ; -- Reset the delimiter to the default semicolon
Stored procedures are a powerful tool in SQL for encapsulating repetitive logic, improving performance, and enhancing securi
rmance, and enhancing security.
WITH RankedSalaries AS (
SELECT salary,
ROW_NUMBER() OVER (ORDER BY salary) AS RowAsc,
ROW_NUMBER() OVER (ORDER BY salary DESC) AS RowDesc
FROM employees
)
SELECT AVG(salary) AS median_salary
FROM RankedSalaries
WHERE RowAsc = RowDesc OR RowAsc + 1 = RowDesc;
SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) AS median_salary
FROM employees;
Atomicity
Consistency
Isolation
Durability
If you are transferring money from one bank account to another, atomicity ensures that both the debit from one account and
If the bank has a rule that no account balance can go below $0, consistency ensures that after any transaction, the account ba
Suppose two people are simultaneously trying to withdraw money from the same bank account. Isolation ensures that each tr
If you transfer money between bank accounts and the system commits the transaction, durability ensures that even if the dat
an invalid state (e.g., an account balance going negative), the transaction will be rejected
see partial updates of the other transaction).
will not be lost. The new balances will still be present when the system recovers.