Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

SQL commands QUESTIONS AND ANSWERS

Rating
-
Sold
-
Pages
14
Grade
A+
Uploaded on
23-05-2022
Written in
2021/2022

AVG() ans: SELECT AVG(COLUMN NAME) FROM TABLE_NAME Using it in WHERE CLAUSE so a different form of presentation: TO LIST ONLY THOSE PRODUCTS AND PRICES WHERE THE AVERAGE IS MORE THAN A SPECIFIC AMOUNT:- SELECT ProductName, Price FROM Products WHERE Price(SELECT AVG(Price) FROM Products); COUNT() ans: SELECT COUNT(*) FROM TABLE_NAME (to select all the NON null values of records in the table SELECT COUNT(Column Name) FROM TABLE_NAME (to count all values in a column) SELECT COUNT(Distinct Column Name) FROM TABLE_NAME (to count all distinct values in a column) SELECT COUNT(Distinct Column Name) as NEWNAME FROM TABLE_NAME (to count all distinct values in a column and label the column with a new name) COUNT DISTINCT VALUES ans: SQL COUNT(DISTINCT column_name) Syntax SELECT COUNT(DISTINCT COLUMN NAME) FROM TABLE_NAME *** Distinct command doesn't work in MS access.Works in SQL and Oracle)*** FIRST() ans: To return the first value of a column. SELECT FIRST(column_name) FROM table_name; ***ONLY IN ACCESS*** Last() ans: To return the last value of a column SELECT LASt(column_name) FROM table_name; AGGREGATE FUNCTIONS ans: •AVG() - Returns the average value •COUNT() - Returns the number of rows •FIRST() - Returns the first value •LAST() - Returns the last value •MAX() - Returns the largest value •MIN() - Returns the smallest value •SUM() - Returns the sum Scalar Functions ans: •UCASE() - Converts a field to upper case •LCASE() - Converts a field to lower case •MID() - Extract characters from a text field •LEN() - Returns the length of a text field •ROUND() - Rounds a numeric field to the number of decimals specified •NOW() - Returns the current system date and time •FORMAT() - Formats how a field is to be displayed

Show more Read less
Institution
Course

Content preview

SQL commands
AVG() ans: SELECT AVG(COLUMN NAME) FROM TABLE_NAME
Using it in WHERE CLAUSE so a different form of presentation:
TO LIST ONLY THOSE PRODUCTS AND PRICES WHERE THE AVERAGE IS MORE THAN A SPECIFIC
AMOUNT:-
SELECT ProductName, Price FROM Products
WHERE Price>(SELECT AVG(Price) FROM Products);

COUNT() ans: SELECT COUNT(*) FROM TABLE_NAME
(to select all the NON null values of records in the table
SELECT COUNT(Column Name) FROM TABLE_NAME
(to count all values in a column)
SELECT COUNT(Distinct Column Name) FROM TABLE_NAME
(to count all distinct values in a column)
SELECT COUNT(Distinct Column Name) as NEWNAME FROM TABLE_NAME
(to count all distinct values in a column and label the column with a new name)

COUNT DISTINCT VALUES ans: SQL COUNT(DISTINCT column_name) Syntax
SELECT COUNT(DISTINCT COLUMN NAME) FROM TABLE_NAME
*** Distinct command doesn't work in MS access.Works in SQL and Oracle)***

FIRST() ans: To return the first value of a column.
SELECT FIRST(column_name) FROM table_name;
***ONLY IN ACCESS***

Last() ans: To return the last value of a column
SELECT LASt(column_name) FROM table_name;

AGGREGATE FUNCTIONS ans: •AVG() - Returns the average value
•COUNT() - Returns the number of rows
•FIRST() - Returns the first value
•LAST() - Returns the last value
•MAX() - Returns the largest value
•MIN() - Returns the smallest value
•SUM() - Returns the sum

Scalar Functions ans: •UCASE() - Converts a field to upper case
•LCASE() - Converts a field to lower case
•MID() - Extract characters from a text field
•LEN() - Returns the length of a text field
•ROUND() - Rounds a numeric field to the number of decimals specified
•NOW() - Returns the current system date and time
•FORMAT() - Formats how a field is to be displayed

, Max() ans: Return the max value from a column
SELECT MAX(Price) AS HighestPrice FROM Products;

Min() ans: Return the min value from a column
SELECT MIN(Price) AS HighestPrice FROM Products;

Sum() ans: Return the sum total of values from a column
SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;

group by ans: The GROUP BY statement is used in conjunction with the aggregate functions to group the
result-set by one or more columns.

>GROUP BY ONE COLUMN
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;

>GROUP BY MORE THAN ONE COLUMN

SELECT Shippers.ShipperName, Employees.LastName,
COUNT(Orders.OrderID) AS NumberOfOrders
FROM ((Orders
INNER JOIN Shippers
ON Orders.ShipperID=Shippers.ShipperID)
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID)
GROUP BY ShipperName,LastName;

Having Clause ans: HAVING clause was added to SQL because the WHERE keyword could not be used
with aggregate functions
>
SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM (Orders
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID)
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 10;
>if LOOKING OUT FOR INFO ON SPECIFIC ENTRY
to identify if a specific employee satisfies the criteria
SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM (Orders
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID)
where lastname="XXX" or Lastname="YYY"
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 10;

U Case ans: The UCASE() function converts the value of a field to uppercase.
Select Ucase(Customername) as Customers,Address FROM Table_Name

Written for

Course

Document information

Uploaded on
May 23, 2022
Number of pages
14
Written in
2021/2022
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Classroom NURSING
Follow You need to be logged in order to follow users or courses
Sold
4874
Member since
4 year
Number of followers
3232
Documents
55394
Last sold
1 day ago
NURSING

Assignments, Case Studies, Research, Essay writing service, Questions and Answers, Discussions etc. for students who want to see results twice as fast. I have done papers of various topics and complexities. I am punctual and always submit work on-deadline. I write engaging and informative content on all subjects. Send me your research papers, case studies, psychology papers, etc, and I’ll do them to the best of my abilities. Writing is my passion when it comes to academic work. I’ve got a good sense of structure and enjoy finding interesting ways to deliver information in any given paper. I love impressing clients with my work, and I am very punctual about deadlines. Send me your assignment and I’ll take it to the next level. I strive for my content to be of the highest quality. Your wishes come first— send me your requirements and I’ll make a piece of work with fresh ideas, consistent structure, and following the academic formatting rules. For every student you refer to me with an order that is completed and paid transparently, I will do one assignment for you, free of charge!!!!!!!!!!!!

Read more Read less
4.0

1185 reviews

5
624
4
216
3
196
2
40
1
109

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions