Welcome to our channel! In this insightful video, we tackle a common SQL interview question: counting the gender distribution of customers. Using a practical example, we demonstrate how to write an SQL query that retrieves the count of customers by gender from a database table. We walk you through the step-by-step process, explaining the necessary SQL syntax and providing valuable tips along the way. Whether you're preparing for a technical interview or simply looking to enhance your SQL skills, this video will equip you with the knowledge and confidence to tackle similar questions with ease. Join us as we unravel the solution and showcase the power of SQL in data analysis.
CREATE TABLE Customers (
Customer_id VARCHAR2(10) PRIMARY KEY,
customer_name VARCHAR2(50),
Age NUMBER,
Gender CHAR(1)
);
-- Insert data into the Customers table
INSERT INTO Customers (Customer_id, customer_name, Age, Gender)
VALUES ('A', 'Steven', 45, 'M');
INSERT INTO Customers (Customer_id, customer_name, Age, Gender)
VALUES ('B', 'Valli', 34, 'F');
INSERT INTO Customers (Customer_id, customer_name, Age, Gender)
VALUES ('C', 'Neena', 27, 'F');
INSERT INTO Customers (Customer_id, customer_name, Age, Gender)
VALUES ('D', 'Lex', 33, 'F');
select * from customers;
CREATE TABLE Transactions (
Tran_id NUMBER PRIMARY KEY,
customer_id VARCHAR2(10) REFERENCES Customers(customer_id),
Tran_date DATE,
tran_type VARCHAR2(1),
Amount NUMBER
);
-- Insert data into the Transactions table
INSERT INTO Transactions (Tran_id, customer_id, Tran_date, tran_type, Amount)
VALUES (101, 'A', TO_DATE('12-10-2023', 'DD-MM-YYYY'), 'C', 450);
INSERT INTO Transactions (Tran_id, customer_id, Tran_date, tran_type, Amount)
VALUES (102, 'B', TO_DATE('13-10-2023', 'DD-MM-YYYY'), 'D', 5000);
INSERT INTO Transactions (Tran_id, customer_id, Tran_date, tran_type, Amount)
VALUES (103, 'A', TO_DATE('14-10-2023', 'DD-MM-YYYY'), 'D', 4590);
INSERT INTO Transactions (Tran_id, customer_id, Tran_date, tran_type, Amount)
VALUES (104, 'A', TO_DATE('16-10-2023', 'DD-MM-YYYY'), 'C', 4050);
INSERT INTO Transactions (Tran_id, customer_id, Tran_date, tran_type, Amount)
VALUES (105, 'C', TO_DATE('18-10-2023', 'DD-MM-YYYY'), 'C', 100);
INSERT INTO Transactions (Tran_id, customer_id, Tran_date, tran_type, Amount)
VALUES (106, 'B', TO_DATE('23-10-2023', 'DD-MM-YYYY'), 'D', 5);
select * from customers;
select * from transactions;
--CUSTOMER GENDER COUNT BASED ON TRANSACTIONS
--joining condition
SELECT GENDER,COUNT(DISTINCT(B.CUSTOMER_ID))
FROM customers A INNER JOIN transactions B ON (A.CUSTOMER_ID=B.CUSTOMER_ID)
GROUP BY GENDER;
#SQLInterviewQuestions #CustomerGenderCount #SQLQuerying #DataAnalysis #SQLSkills #DatabaseManagement #SQLTutorial #SQLTips #InterviewPreparation #TechnicalInterview #SQLSyntax #DataManipulation #SQLQueryExample #SQLSolutions #DataInsights #SQLProgramming #SQLLearning #SQLPractices #jobinterviewtips