0% found this document useful (0 votes)
19 views

Database Management System Lab_9_1738999516683

This document is an assignment for BCA Sem-I students at Rajarshi Shahu College of Engineering, focusing on DDL commands in SQL. It covers key SQL concepts such as GROUP BY, ORDER BY, HAVING, and SELECT DISTINCT, along with syntax and examples. Students are required to solve specific queries and attach their program outputs to demonstrate their understanding of these commands.

Uploaded by

janhavik053
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Database Management System Lab_9_1738999516683

This document is an assignment for BCA Sem-I students at Rajarshi Shahu College of Engineering, focusing on DDL commands in SQL. It covers key SQL concepts such as GROUP BY, ORDER BY, HAVING, and SELECT DISTINCT, along with syntax and examples. Students are required to solve specific queries and attach their program outputs to demonstrate their understanding of these commands.

Uploaded by

janhavik053
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

JSPM’s

RAJARSHI SHAHU COLLEGE OF ENGINEERING


TATHAWADE, PUNE-33
(An Autonomous Institute Affiliated to Savitribai Phule Pune University, Pune)

Department of Computer Applications


BCA Sem-I
Subject: DBMS

Assignment 9

Aim: Introduction to DDL Commands

Problem statement: Using Order By, Group By, With Clause, Having Clause, Distinct
keyword

Requirements: SQL Compiler

Operating system: Windows/Linux

Theory:

Assume Tables already created.


The SQL Group BY Statement

 The GROUP BY statement groups rows that have the same values into summary
rows, like "find the number of customers in each country".
 The GROUP BY statement is often used with aggregate functions
(COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more
columns.

GROUP BY Syntax

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);

Example:

SELECT country, COUNT(Country) as Number


FROM Customers
GROUP BY country;
The SQL ORDER BY

The ORDER BY keyword is used to sort the result-set in ascending or descending order.

Order By Syntax

SELECT column1, column2, ...


FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

Eg. SELECT * FROM Customers


ORDER BY age ASC;

The SQL HAVING Clause

The HAVING clause was added to SQL because the WHERE keyword cannot be used with
aggregate functions.
HAVING SyntaxSELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
Eg.
SELECT customer_id, SUM(amount) AS total
FROM Orders
Group by customer_id
HAVING SUM(amount) < 700;
The SQL SELECT DISTINCT Statement

The SELECT DISTINCT statement is used to return only distinct (different) values.

SELECT DISTINCT column_name from table_name;

Eg.

SELECT DISTINCT age


FROM Customers;

Solve the following queries:

1. Display the Count the number of orders of each item.


Ans. SELECT COUNT(order_id), item FROM Orders GROUP BY item;
2. Display Orders all rows from Customers in ascending order of country
Ans. SELECT * FROM Customers ORDER BY country;
3. Select customers with the same first name based on their age count.
Ans.
SELECT COUNT(age) AS Count, first_name
FROM Customers
GROUP BY first_name
HAVING COUNT(age) > 1;
4. Select the unique countries from the customers table.
Ans.
SELECT DISTINCT country
FROM Customers;

Output: Student should attach the output of program

Conclusion: Student will be able to execute DML Commands;

You might also like