Practical data management and SQL
- Details
- Category: 12th class computer practical's.
- Published: Friday, 11 June 2021 07:57
- Written by Super User
- Hits: 403
SQL queries
Find max marks from students table
Select max(marks) maximum_marks
From students
Explanantion: In this query we have used max inbuilt function of mySQL and renamed the max(marks) result display column as maximum_marks. max function takes column name as argument and return the highest value from column data.
Find minimum marks from students table
Select min(marks) minimum_marks
From students
Explanation: In this query we have used min inbuilt function of mySQL and renamed the results column as minimum_marks.
Find Average of marks from students table
Select avg(marks) average_marks
From students
In this query we have used avg inbuilt function of mySQL and renamed the results column as average_marks.
Find sum of marks from students table
Select sum(marks) sum_of_marks
From students
In this query we have used sum inbuilt function of mySQL and renamed the results column as sum_of_marks.
Find number of customers from each country using group by query from customers table
Select count(customerid) total_customers,country
From Customers
Group by country
Explanation: In this query we have used count inbuilt function of mySQL to count total customers by their customer id and renamed the results column as total_customers. We used group by here to find total customers for each country(group by each country). So the above query will show total customers for each country in the results columns like below. we are considering that customerid is unique in customers table.
total_customers + Country
+++++++++++++++++
10 + America
23 + Iran
13 + India
17 + Korea
Write a SQL query to order the (student ID, marks) table in descending order of the marks.
Select studentid, marks
From students
Order by marks desc
Explanation: In this query we have used order by clause in query. We used order by with respect to marks column and used desc keyword to order the results columns in descending order of marks.