SQL Queries for Student Data Analysis
SQL Queries for Student Data Analysis
To find students with 'n' as the second letter in their names, the query uses the LIKE operator: SELECT Name FROM STU WHERE Name LIKE '_n%'. This pattern matches names where the second character is 'n', '_' matches any first character, and '%' matches the following sequence .
To count male and female students in the STU table, group by gender and use the COUNT() function: SELECT Gender, COUNT(*) FROM STU GROUP BY Gender. This groups rows by Gender and counts the number of students in each group, effectively separating male and female student counts .
To find students aged between 20 and 25, you would use the following SQL statement: SELECT Name FROM STU WHERE Age BETWEEN 20 AND 25. This sets an age range filter to retrieve the list of student names .
To display names and ages in descending order by age, the query is: SELECT Name, Age FROM STU ORDER BY Age DESC. This sorts the results by Age in descending order .
To retrieve names where the department is NULL, use the query: SELECT Name FROM STU WHERE Department IS NULL. This filters the results to show only those students whose Department field contains NULL values .
To display female students in the Hindi Department, the query needs to filter on gender and department: SELECT Name FROM STU WHERE Gender = 'Female' AND Department = 'Hindi'. This SQL command selects the names of all students whose Gender is Female and who are enrolled in the Hindi Department .
To find distinct departments in the STU table, you use the SELECT DISTINCT statement: SELECT DISTINCT Department FROM STU. This returns a list of unique department values without duplicates .
To show all information about History department students, use: SELECT * FROM STU WHERE Department = 'History'. This selects all columns where the Department is History, thereby returning complete student records .
To list all students whose names start with 'A', you can use the SQL SELECT statement with the LIKE operator. The query would be: SELECT * FROM STU WHERE Name LIKE 'A%'. This retrieves all rows from the STU table where the Name column begins with 'A' .
To display details of students from the Computer department, the SQL query is: SELECT * FROM STU WHERE Department = 'Computer'. This selects all columns for rows where the Department is specified as Computer, thus providing full details .