You are on page 1of 7

e-sensor population database create table with uniqe id ,

name ,age,gender,religion ,cast,city,district, state for , country with sql

code:

CREATE TABLE population_country (

id INT PRIMARY KEY,

name VARCHAR(50) NOT NULL,

age INT,

gender VARCHAR(10),

religion VARCHAR(20),

caste VARCHAR(20),

city VARCHAR(50),

district VARCHAR(50),

state VARCHAR(50),

country VARCHAR(50) NOT NULL DEFAULT 'India'

);

Data:

INSERT INTO population_country (id, name, age, gender, religion, caste, city, district, state)

VALUES

(1, 'Amit Kumar', 32, 'Male', 'Hindu', 'SC', 'Patna', 'Patna', 'Bihar'),

(2, 'Rajesh Singh', 27, 'Male', 'Hindu', 'ST', 'Jamshedpur', 'East Singhbhum', 'Jharkhand'),

(3, 'Gopal Sharma', 45, 'Male', 'Hindu', 'General', 'Kolkata', 'North 24 Parganas', 'West Bengal'),

(4, 'Anil Singh', 18, 'Male', 'Hindu', 'SC', 'Bhagalpur', 'Bhagalpur', 'Bihar'),

(5, 'Sunil Yadav', 38, 'Male', 'Hindu', 'ST', 'Purulia', 'Purulia', 'West Bengal'),

(6, 'Suresh Patel', 26, 'Male', 'Hindu', 'General', 'Darbhanga', 'Darbhanga', 'Bihar'),

(7, 'Alok Singh', 40, 'Male', 'Sikh', 'General', 'Kolkata', 'Kolkata', 'West Bengal'),

(8, 'Jasdeep Kaur', 29, 'Female', 'Sikh', 'General', 'Patna', 'Patna', 'Bihar'),

(9, 'Priya Mishra', 22, 'Female', 'Hindu', 'SC', 'Gaya', 'Gaya', 'Bihar'),

(10, 'Renuka Devi', 35, 'Female', 'Hindu', 'ST', 'Munger', 'Munger', 'Bihar'),

(11, 'Rohit Kumar', 8, 'Child', 'Hindu', 'SC', 'Darbhanga', 'Darbhanga', 'Bihar'),

(12, 'Mohan Sharma', 12, 'Child', 'Hindu', 'ST', 'Purulia', 'Purulia', 'West Bengal'),
(13, 'Arun Kumar', 5, 'Child', 'Hindu', 'General', 'Kolkata', 'North 24 Parganas', 'West Bengal'),

(14, 'Rajni Devi', 7, 'Child', 'Hindu', 'General', 'Patna', 'Patna', 'Bihar'),

(15, 'Kamaljeet Kaur', 34, 'Transgender', 'Sikh', 'General', 'Patna', 'Patna', 'Bihar'),

(16, 'Sandeep Singh', 21, 'Transgender', 'Hindu', 'SC', 'Asansol', 'Paschim Bardhaman', 'West Bengal'),

(17, 'Nisha Devi', 27, 'Transgender', 'Hindu', 'ST', 'Gaya', 'Gaya', 'Bihar');

1. List the number of male and female persons in West Bengal.

2. Find out the no. of child whose age is between 5-10 years in Bihar.

3. List the name of Sikh Community belongs in West Bengal.

4. Find the number Transgender in Bihar.

5. Find the number of population state wise.

6. List the district where females are more in number.

7. List the states which have less no. of population.

8. List the female members whose age is less than 40 years from different states.

9. Find the number of male and female persons in India state wise.

10. List the state where maximum number of male persons whose age is more than 50 years.

11. Count the number of people in India state wise where they belong in SC and ST category.

12. Find the district in west Bengal where population is more in number.

13. Find the districts and it’s state where the population is below 5 lakhs.

14. Find the count of male and female persons in the district Hooghly,  West Bengal.

SELECT gender, COUNT(*) AS count

FROM population_country

WHERE state = 'West Bengal'

GROUP BY gender;
SELECT COUNT(*) AS count

FROM population_country

WHERE state = 'Bihar' AND age BETWEEN 5 AND 10;

SELECT name

FROM population_country

WHERE religion = 'Sikh' AND state = 'West Bengal';

SELECT COUNT(*) AS count

FROM population_country

WHERE state = 'Bihar' AND gender = 'Transgender';

SELECT state, COUNT(*) AS count

FROM population_country

GROUP BY state;

SELECT district, COUNT(*) AS count

FROM population_country
WHERE gender = 'Female'

GROUP BY district

HAVING COUNT(*) > (SELECT COUNT(*)/2 FROM population_country WHERE gender = 'Male')

SELECT state, COUNT(*) AS count

FROM population_country

GROUP BY state

HAVING COUNT(*) < 10;

SELECT name, age, state

FROM population_country

WHERE gender = 'Female' AND age < 40;


SELECT state, gender, COUNT(*) AS count

FROM population_country

GROUP BY state, gender;

SELECT state, COUNT(*) AS count

FROM population_country

WHERE gender = 'Male' AND age > 50

GROUP BY state

ORDER BY count DESC

LIMIT 1;

SELECT state, cast, COUNT(*) AS count

FROM population_country

WHERE cast IN ('SC', 'ST')


GROUP BY state, cast;

SELECT district, COUNT(*) AS count

FROM population_country

WHERE state = 'West Bengal'

GROUP BY district

ORDER BY count DESC

LIMIT 1;

SELECT district, state, COUNT(*) AS count

FROM population_country

GROUP BY district, state

HAVING COUNT(*) < 500000;


SELECT gender, COUNT(*) AS count

FROM population_country

WHERE district = 'Hooghly' AND state = 'West Bengal'

GROUP BY gender;

You might also like