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

Praktikum Basis Data: Data Manipulation Language (DML)

The document discusses several SQL clauses and functions for data manipulation: The SELECT TOP clause allows selecting the top number or percentage of records from a table. The MIN() and MAX() functions return the smallest or largest value of a column. The COUNT(), AVG(), and SUM() functions return the number of rows, average, and total sum of values in a column. The GROUP BY statement groups query results by one or more columns, and is often used with aggregate functions. The HAVING clause was added to use conditions with aggregate functions since WHERE cannot be used with them.

Uploaded by

Angga Astawa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Praktikum Basis Data: Data Manipulation Language (DML)

The document discusses several SQL clauses and functions for data manipulation: The SELECT TOP clause allows selecting the top number or percentage of records from a table. The MIN() and MAX() functions return the smallest or largest value of a column. The COUNT(), AVG(), and SUM() functions return the number of rows, average, and total sum of values in a column. The GROUP BY statement groups query results by one or more columns, and is often used with aggregate functions. The HAVING clause was added to use conditions with aggregate functions since WHERE cannot be used with them.

Uploaded by

Angga Astawa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

PRAKTIKUM BASIS DATA

DATA MANIPULATION LANGUAGE (DML)


The SQL SELECT TOP Clause
The SELECT TOP clause is useful on large tables with thousands of
records. Returning a large number of records can impact on
performance.

SELECT TOP number|percent


column_name(s)
FROM table_name
WHERE condition;

SELECT TOP 3 * FROM Customers;


SELECT TOP 50 PERCENT * FROM Customers;
The SQL MIN() and MAX() Functions
The MIN() function returns the smallest value of the selected column.

The MAX() function returns the largest value of the selected column.

SELECT MIN(column_name)
FROM table_name
WHERE condition;

SELECT MAX(column_name)
FROM table_name
WHERE condition;
The SQL COUNT(), AVG() and SUM()
Functions
The COUNT() function returns the number of rows that matches a
specified criteria.
The AVG() function returns the average value of a numeric
column.
The SUM() function returns the total sum of a numeric column.

SELECT COUNT | AVG | SUM (column_name)


FROM table_name
WHERE condition;
The SQL GROUP BY Statement
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.

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country;

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;
The SQL HAVING Clause
The HAVING clause was added to SQL because the WHERE
keyword could not be used with aggregate functions.

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5
ORDER BY COUNT(CustomerID) DESC;
THE END

You might also like