A Guide to SQL
A Guide to SQL
9th Edition
ISBN: 9781111527273
Author: Philip J. Pratt
Publisher: Course Technology Ptr
bartleby

Concept explainers

Question
Book Icon
Chapter 4, Problem 20TD
Program Plan Intro

“SELECT” command:

The “SELECT” command is used to retrieve data in a database.

Syntax for selecting values from the table is as follows:

SELECT STUDENT_ID FROM STUDENT;

  • The given query is used to display each student ID from “STUDENT” table.

“ORDER BY” Clause:

  • User can sort the data in specific order using “ORDER BY” clause.
  • The column on which to sort data is called a sort key or a simple key.
  • To sort the output, use an “ORDER BY” clause followed by the sort key.
  • If the user does not indicate a sort order, the output displayed in default order that is ascending order.

Example:

The example for “ORDER BY” clause is given below:

SELECT STUDENT_ID, STUDENT_NAME, STUDENT_CREDIT FROM STUDENT ORDER BY STUDENT_CREDIT;

 The above query is used to list student ID, name and credit for each student with ascending order of student credit using an “ORDER BY” clause.

  • From the given query, the sort key is “STUDENT_CREDIT”. So, the rows are sorted in ascending order by “STUDENT_CREDIT”.

“GROUP BY” Clause:

  • User can group the data using “GROUP BY” clause.
  • This clause allows the user to group data on a specific column and then computes statistics when user preferred.

Example:

The example for “GROUP BY” clause is given below:

SELECT CUSTOMER_NAME, SUM(AMOUNT) FROM CUSTOMERS GROUP BY CUSTOMER_NAME;

The above query is used to list the customer name and the sum of amount using “GROUP BY” clause.

“HAVING” Clause:

  • The “HAVING” clause is used to restrict the groups that are included.
    • This restriction does not apply to individual rows but relatively apply to groups.

Example:

The example for “HAVING” clause is given below:

SELECT STUDENT_ID, NAME, AGE, ADDRESS, TOTAL_MARK FROM STUDENTS GROUP BY AGE HAVING COUNT(AGE) >= 10;

  • The above query is used to display a record for a similar age count that would be more than or equal to “10”.

Blurred answer
Students have asked these similar questions
What did you find most interesting or surprising about the scientist Lavoiser?
1. Complete the routing table for R2 as per the table shown below when implementing RIP routing Protocol? (14 marks) 195.2.4.0 130.10.0.0 195.2.4.1 m1 130.10.0.2 mo R2 R3 130.10.0.1 195.2.5.1 195.2.5.0 195.2.5.2 195.2.6.1 195.2.6.0 m2 130.11.0.0 130.11.0.2 205.5.5.0 205.5.5.1 R4 130.11.0.1 205.5.6.1 205.5.6.0
Analyze the charts and introduce each charts by describing each. Identify the patterns in the given data. And determine how are the data points are related.   Refer to the raw data (table):

Chapter 4 Solutions

A Guide to SQL

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
A Guide to SQL
Computer Science
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Course Technology Ptr
Text book image
Oracle 12c: SQL
Computer Science
ISBN:9781305251038
Author:Joan Casteel
Publisher:Cengage Learning
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage
Text book image
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L