SlideShare a Scribd company logo
1 of 7
SQL
Exercises

Name:

Instructions:

Go to File → Programs → IT → SQL Userguide. Read the associated Chapter and then
complete the theory and Practical exercises. This file is saved on shared (SQL Exercises).
Type in your responses for both review questions and practical exercises .

Chapter
4Review Questions
1.
2.
3.
4.
5.
6.
7.

When may the From clause be omitted from a query?
What determines the number of columns displayed in a result table?
How is the order of columns in a result table determined?
What are the two ways of specifying an item in the Order By clause?
State the abbreviations used by SQL for ascending and descending in the Order By clause.
How are the rows in a result table ordered when two items are included in an Order By clause?
Explain the different effects of the all and distinct keywords when used in the Select clause of a
query.
8. How may commands, queries and result tables be printed in microSQL?
9. How does microSQL indicate that a result table is too wide to fit on the display?
10. If a result table is too large to fit entirely on the display screen, how may the keyboard and mouse
be used to view information not initially visible?

Exercises
Express each of the following queries as a valid SQL Select command:
1.
2.
3.
4.
5.

List the name of each recent prime minister together with his spouse's name, marriage year and
number of children.
Display the name, state born and death age, in that order, for each recent prime minister.
Retrieve full details of all marriages for recent prime ministers and order the result on descending
values of marriage year.
For each recent prime minister list the name, state born, death age and birth year. Order the result
on death age descending, within ascending values of state born.
List the different states in which a recent prime minister was born.
Chapter
5

Review Questions
1.
2.
3.
4.
5.
6.

What is a search condition?
Explain the function of the Where clause in an SQL query.
List the comparison operators provided by SQL and indicate the meaning of each.
Why is it necessary to enclose character constants in quotes?
Explain how null values are handled by SQL when a condition containing a comparison operator
is evaluated.
What syntax is used when the null keyword appears in a condition?

Exercises
Write valid Select commands for the following queries:
1.
2.
3.
4.
5.
6.
7.
8.

Retrieve all the information in the prime_minister table about Bob Hawke.
Get full details of all marriages where there were fewer than two children.
Which prime ministers had cycling as a recreation?
List the names of all deputy prime ministers who belonged to the Labor party.
Find the names of all prime ministers who were commissioned after 1960.
Retrieve the spouse name and marriage year for those prime ministers who married before age 30.
Which prime ministers represented the same state that they were born in?
List the name and number of years served for the prime ministers who died before they were 80. Order the
result by descending values of years served.
9. Get full details of the prime minister who is still in office.
10. List the names of all prime ministers who were born in Australia.

Chapter
6
Review Questions
1.
2.
3.
4.
5.

List the logical operators in order of precedence.
What function do parentheses perform when used in search conditions?
Explain the difference in effect of the and and or logical operators.
Suppose that rows are to be retrieved from the prime minister table where the value of years served is not less
than 4. Formulate the appropriate search condition in all possible ways.
Suggest uses for the bit data type when combined with bitwise operations.

Exercises
Write a Select command for each of the following queries:
1.
2.

Which prime ministers belonged to the Liberal party and were commissioned after 1950?
List the names of prime ministers who were married by age 30 or after 1900.
3.
4.
5.
6.

Find the names of prime ministers who had golf or tennis as a recreation.
Retrieve full details of marriages where the year of marriage was earlier than 1910, the prime
minister was at least 35 when he married, and there were not less than two children from the
marriage.
List the name and year of birth for prime ministers who were born in Tasmania or represented
Queensland and also served at least 4 years or died aged 60.
Which prime ministers were born in or represented Victoria, but not both?

Chapter
7
Review Questions
1.
2.
3.
4.
5.

List the special operators provided by SQL and state the function of each.
State any special requirement when using a column name and constants with the between and in operators.
What meanings do the underscore and percent characters have when used with the like operator?
Describe some possible uses for the like and part operators.
What is an escape character? When is it necessary to use an escape character with the like operator?

Exercises
Write valid Select commands containing the between, in, like or part operators for the following queries:
1.
2.
3.
4.
5.
6.
7.
8.

Which prime ministers had between 2 and 4 children inclusive in any marriage?
List the names of prime ministers who had cricket, golf or tennis as a recreation.
Find the names of prime ministers and their parties where the party name does not begin with 'L'.
Who were the deputy prime ministers in ministries numbered 20, 30, 35 and 40?
Which prime ministers were not born in New South Wales or Victoria?
List full details of all marriages where the spouse name begins with 'L' and the second letter is not
'a' or 'e'.
Which prime ministers had recreations described by two words?
Find the prime ministers who were born in a state which has a name containing the character 'A'.

Chapter 8
Review Questions
1.
2.
3.
4.
5.

Where may arithmetic expressions occur in an SQL Select command?
What arithmetic operators are available in SQL? List them in order of precedence.
How can the column names in a result table be turned off in microSQL?
Describe what happens when character items are concatenated.
What symbol is used for the SQL concatenation operator?

Exercises
Write a Select command for each of the following:
1.

List the current age of all prime ministers who are still alive.
2.
3.
4.
5.

In which year did Harold Holt die?
How many years ago was each prime minister married?
List the ages of prime ministers who were alive in 1920. Order the result on descending values of
age.
List each Australian-born prime minister together with an appropriate message and his state of
birth (use only one item in the Select clause of your query).

Chapter 9
Review Questions
1.
2.
3.
4.
5.
6.

Explain how aggregate and scalar functions differ.
List the aggregate functions provided by microSQL.
What rules must be followed when aggregate functions are used in a query?
Describe the three ways in which the Count function may be used and state the meaning of the value returned
in each case.
List the scalar functions provided by microSQL. State the purpose of each.
How many characters are normally returned when a number is converted to character? How may this be
changed?

7.

What determines whether the characters returned by the Cast function are left or right justified? What is a fill
character and how is one specifed in the case of a right-justified result?
8. State the rules that apply to arguments used with the microSQL date functions.
9. List the date functions provided by microSQL and state the purpose of each.
10. How may a date in short or US short format be converted to a decimal date?

Exercises
Write Select commands for each of the following:
1.

List the total, average, and standard deviation of the years served by prime ministers who
represented New South Wales.
2. How many children have resulted from the marriages of all Australian prime ministers?
3. Find the number of times that different prime ministers have been commissioned.
4. Which prime minister who represented Victoria died at the greatest age?
5. How many years ago was Malcolm Fraser first commissioned as prime minister?
6. In how many ministries did John Gorton serve as prime minister? What were the numbers of his
first and last ministries?
7. How many years is it since a prime minister who represented the Country party was
commissioned?
8. List each prime minister's name together with the date(s) on which he was commissioned in the
format mm-dd-yyyy.
9. Find the approximate number of years and months that each prime minister served.
10. How many more days would Malcolm Fraser have had to serve to complete his last year of
service?
11. Calculate the number of days John Howard has served since first being commissioned as prime
minister?
12. Find the interval in days between the dates of Gough Whitlam's first and last commissionings.
13. Write the select-expression which produced the following result table:
Barton E died at age 71
Deakin A died at age 63
Watson J C died at age 74
14. For each prime minister who belonged to a party having two words in its name, list the names of
the prime minister and party in the precise format indicated:
Reid G H ( Free Trade )
Hughes W M ( National Labor )

Chapter
10 Questions
Review
1.
2.
3.

What is an unconstrained join?
Explain what happens when an equijoin of two tables is performed.
Define the term domain. Why should the join operation be restricted to tables which have column values
drawn from a common domain?
4. What is an alias? How are aliases assigned to tables in a query?
5. Explain how a table can be joined to itself in SQL.
6. Define the terms inner join and natural join.
7. When is it necessary to specify an outer join? What types of outer join are available in SQL?
8. When would the using clause occur in a join?
9. What is the purpose of the on clause in an SQL join?
10. Describe the result table for a cross join and union join.

Exercises
Write Select commands for each of the following; use the SQL join operator in 3 to 6 inclusive:
1.
2.
3.
4.
5.
6.

For each prime minister, list his name, the name of his spouse, and the party to which he belonged
as prime minister.
List the names of the prime minister and deputy prime minister for each ministry since federation.
Display the name of each prime minister born in Victoria together with the names of his recorded
recreations.
For each prime minister, list his name and party. Include in the report the party to which he
belonged, if any, as deputy prime minister.
List the name, birth year, marriage year, recreations, and ministry numbers of the ministries in
which he served, for all prime ministers who were born after 1900 and married before 1950. Order
the result on ascending values of marriage year within birth year.
Display in pairs the names of prime ministers who were married in the same year. Also include the
marriage year in the result.
Chapter
11

Review Questions
1.
2.
3.
4.
5.

What is the effect of including a Group By clause in an SQL query?
State the rules that must be followed when using grouping.
Describe the difference between search conditions when used in Where and Having clauses.
In what order are search conditions in Where and Having clauses applied when SQL executes a query?
How are rows ordered by microSQL if a query contains a Group By clause but not an Order By clause?

Exercises
Write Select commands for the following queries:
1.
2.
3.
4.
5.
6.
7.
8.

Find the average death age for prime ministers born in each state.
How many deputy prime ministers have come from each party? How many different deputies have
there been (from each party)?
Including only prime ministers born in Australia, list the total number of prime ministers who
represented each state.
For each birth state, list the age of the prime minister who lived the longest.
List the names of those prime ministers who had more marriages than they had children from all
their marriages.
Which parties have had more than two different prime ministers commissioned? List the result in
descending order of number commissioned.
List the prime ministers who married more than once, and had at least one child from each
marriage.
Which prime ministers who married more than once had at least one child from any of their
marriages?

Chapter
12

Review Questions
1.
2.
3.
4.
5.
6.

State the rules for formulating subqueries in SQL.
What are the differences between the result returned by a main query and that returned by a subquery?
Explain how the any and all qualifiers are used to create set comparison operators in SQL.
Which other set comparison operators are equivalent to in and not in?
When may an ordinary comparison operator be used to test the result returned by a subquery?
Distinguish between nested and multiple subqueries.

Exercises
Write Select commands containing subqueries for the following:
1.

Find the name and age at death of the prime minister who died at the greatest age.
2.
3.
4.
5.
6.
7.
8.
9.

List the names and years served for those prime ministers who were in office for more than the
average number of years.
Obtain full details of the marriage of the prime minister who was commissioned the most times.
Which prime ministers also served as deputy prime minister?
Find the name and state represented for those prime ministers who belonged to at least two
different parties as deputy prime minister.
List the name, birth state and year of birth for the Labor prime minister who had the maximum
number of recorded recreations.
Which prime minister had more than three children, represented New South Wales while
belonging to the Labor party, and was deputy prime minister while a member of the United
Australia party?
Retrieve the name, birth state and years served for the prime ministers who married after 1950
and were commissioned at least twice.
Find the state that has been represented by the most prime ministers.

Chapter
13 Questions
Review
1.
2.
3.
4.
5.

Distinguish between correlated and noncorrelated subqueries.
What is a correlation condition?
A noncorrelated subquery is evaluated only once but a correlated subquery must be evaluated many times.
Why?
When is a condition that uses the exists operator satisfied?
Why is it permissible to use an asterisk as the item to be selected in a subquery that follows exists?

Exercises
Use correlated subqueries in formulating Select commands for the following:
1.
2.
3.
4.
5.
6.

Find the name, and age when first married, of those prime ministers who were married twice.
Which prime ministers were commissioned before they were first married?
For the Labor prime ministers who were commissioned more than once, find the year when they
were commissioned for the second time.
Which prime ministers were commissioned twice as many times as they were married?
List the names of prime ministers who were first commissioned within twenty years of their (first)
marriage.
Find the number of times that a member of the Labor party has been deputy prime minister and
prime minister in consecutive ministries.

Use the exists operator in Exercises 7 - 10.
7.
8.
9.

Which prime ministers also served as deputy prime minister?
Find the names of prime ministers who had at least one of Bob Hawke's recreations.
List the name and party of prime ministers who belonged to another party as deputy prime
minister.
10. Which prime ministers were commissioned at least twice and served as deputy prime minister
after they were first commissioned?

More Related Content

More from hccit

University partnerships programs email
University partnerships programs emailUniversity partnerships programs email
University partnerships programs emailhccit
 
Griffith sciences pathway programs overview
Griffith sciences pathway programs overviewGriffith sciences pathway programs overview
Griffith sciences pathway programs overviewhccit
 
Griffith info tech brochure
Griffith info tech brochureGriffith info tech brochure
Griffith info tech brochurehccit
 
Repairs questions
Repairs questionsRepairs questions
Repairs questionshccit
 
Movies questions
Movies questionsMovies questions
Movies questionshccit
 
Australian birds questions
Australian birds questionsAustralian birds questions
Australian birds questionshccit
 
Section b
Section bSection b
Section bhccit
 
Section a
Section aSection a
Section ahccit
 
Ask manual rev5
Ask manual rev5Ask manual rev5
Ask manual rev5hccit
 
Case study report mj
Case study report mjCase study report mj
Case study report mjhccit
 
Mj example case_study_layout_intro_completedq
Mj example case_study_layout_intro_completedqMj example case_study_layout_intro_completedq
Mj example case_study_layout_intro_completedqhccit
 
Case study plan mj
Case study plan mjCase study plan mj
Case study plan mjhccit
 
Checklist 12 ict
Checklist 12 ictChecklist 12 ict
Checklist 12 icthccit
 
2013 online communications_blog_11_ict
2013 online communications_blog_11_ict2013 online communications_blog_11_ict
2013 online communications_blog_11_icthccit
 
Year 12 ipt key dates for completion
Year 12 ipt   key dates for completionYear 12 ipt   key dates for completion
Year 12 ipt key dates for completionhccit
 
Senior ipt term4_casestudy
Senior ipt term4_casestudySenior ipt term4_casestudy
Senior ipt term4_casestudyhccit
 
Robotics assignment
Robotics assignmentRobotics assignment
Robotics assignmenthccit
 
10 ict gm_game_assignment_2013
10 ict gm_game_assignment_201310 ict gm_game_assignment_2013
10 ict gm_game_assignment_2013hccit
 

More from hccit (20)

University partnerships programs email
University partnerships programs emailUniversity partnerships programs email
University partnerships programs email
 
Griffith sciences pathway programs overview
Griffith sciences pathway programs overviewGriffith sciences pathway programs overview
Griffith sciences pathway programs overview
 
Griffith info tech brochure
Griffith info tech brochureGriffith info tech brochure
Griffith info tech brochure
 
Repairs questions
Repairs questionsRepairs questions
Repairs questions
 
Movies questions
Movies questionsMovies questions
Movies questions
 
Australian birds questions
Australian birds questionsAustralian birds questions
Australian birds questions
 
Section b
Section bSection b
Section b
 
B
BB
B
 
A
AA
A
 
Section a
Section aSection a
Section a
 
Ask manual rev5
Ask manual rev5Ask manual rev5
Ask manual rev5
 
Case study report mj
Case study report mjCase study report mj
Case study report mj
 
Mj example case_study_layout_intro_completedq
Mj example case_study_layout_intro_completedqMj example case_study_layout_intro_completedq
Mj example case_study_layout_intro_completedq
 
Case study plan mj
Case study plan mjCase study plan mj
Case study plan mj
 
Checklist 12 ict
Checklist 12 ictChecklist 12 ict
Checklist 12 ict
 
2013 online communications_blog_11_ict
2013 online communications_blog_11_ict2013 online communications_blog_11_ict
2013 online communications_blog_11_ict
 
Year 12 ipt key dates for completion
Year 12 ipt   key dates for completionYear 12 ipt   key dates for completion
Year 12 ipt key dates for completion
 
Senior ipt term4_casestudy
Senior ipt term4_casestudySenior ipt term4_casestudy
Senior ipt term4_casestudy
 
Robotics assignment
Robotics assignmentRobotics assignment
Robotics assignment
 
10 ict gm_game_assignment_2013
10 ict gm_game_assignment_201310 ict gm_game_assignment_2013
10 ict gm_game_assignment_2013
 

Recently uploaded

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

SQL Exercises Guide

  • 1. SQL Exercises Name: Instructions: Go to File → Programs → IT → SQL Userguide. Read the associated Chapter and then complete the theory and Practical exercises. This file is saved on shared (SQL Exercises). Type in your responses for both review questions and practical exercises . Chapter 4Review Questions 1. 2. 3. 4. 5. 6. 7. When may the From clause be omitted from a query? What determines the number of columns displayed in a result table? How is the order of columns in a result table determined? What are the two ways of specifying an item in the Order By clause? State the abbreviations used by SQL for ascending and descending in the Order By clause. How are the rows in a result table ordered when two items are included in an Order By clause? Explain the different effects of the all and distinct keywords when used in the Select clause of a query. 8. How may commands, queries and result tables be printed in microSQL? 9. How does microSQL indicate that a result table is too wide to fit on the display? 10. If a result table is too large to fit entirely on the display screen, how may the keyboard and mouse be used to view information not initially visible? Exercises Express each of the following queries as a valid SQL Select command: 1. 2. 3. 4. 5. List the name of each recent prime minister together with his spouse's name, marriage year and number of children. Display the name, state born and death age, in that order, for each recent prime minister. Retrieve full details of all marriages for recent prime ministers and order the result on descending values of marriage year. For each recent prime minister list the name, state born, death age and birth year. Order the result on death age descending, within ascending values of state born. List the different states in which a recent prime minister was born.
  • 2. Chapter 5 Review Questions 1. 2. 3. 4. 5. 6. What is a search condition? Explain the function of the Where clause in an SQL query. List the comparison operators provided by SQL and indicate the meaning of each. Why is it necessary to enclose character constants in quotes? Explain how null values are handled by SQL when a condition containing a comparison operator is evaluated. What syntax is used when the null keyword appears in a condition? Exercises Write valid Select commands for the following queries: 1. 2. 3. 4. 5. 6. 7. 8. Retrieve all the information in the prime_minister table about Bob Hawke. Get full details of all marriages where there were fewer than two children. Which prime ministers had cycling as a recreation? List the names of all deputy prime ministers who belonged to the Labor party. Find the names of all prime ministers who were commissioned after 1960. Retrieve the spouse name and marriage year for those prime ministers who married before age 30. Which prime ministers represented the same state that they were born in? List the name and number of years served for the prime ministers who died before they were 80. Order the result by descending values of years served. 9. Get full details of the prime minister who is still in office. 10. List the names of all prime ministers who were born in Australia. Chapter 6 Review Questions 1. 2. 3. 4. 5. List the logical operators in order of precedence. What function do parentheses perform when used in search conditions? Explain the difference in effect of the and and or logical operators. Suppose that rows are to be retrieved from the prime minister table where the value of years served is not less than 4. Formulate the appropriate search condition in all possible ways. Suggest uses for the bit data type when combined with bitwise operations. Exercises Write a Select command for each of the following queries: 1. 2. Which prime ministers belonged to the Liberal party and were commissioned after 1950? List the names of prime ministers who were married by age 30 or after 1900.
  • 3. 3. 4. 5. 6. Find the names of prime ministers who had golf or tennis as a recreation. Retrieve full details of marriages where the year of marriage was earlier than 1910, the prime minister was at least 35 when he married, and there were not less than two children from the marriage. List the name and year of birth for prime ministers who were born in Tasmania or represented Queensland and also served at least 4 years or died aged 60. Which prime ministers were born in or represented Victoria, but not both? Chapter 7 Review Questions 1. 2. 3. 4. 5. List the special operators provided by SQL and state the function of each. State any special requirement when using a column name and constants with the between and in operators. What meanings do the underscore and percent characters have when used with the like operator? Describe some possible uses for the like and part operators. What is an escape character? When is it necessary to use an escape character with the like operator? Exercises Write valid Select commands containing the between, in, like or part operators for the following queries: 1. 2. 3. 4. 5. 6. 7. 8. Which prime ministers had between 2 and 4 children inclusive in any marriage? List the names of prime ministers who had cricket, golf or tennis as a recreation. Find the names of prime ministers and their parties where the party name does not begin with 'L'. Who were the deputy prime ministers in ministries numbered 20, 30, 35 and 40? Which prime ministers were not born in New South Wales or Victoria? List full details of all marriages where the spouse name begins with 'L' and the second letter is not 'a' or 'e'. Which prime ministers had recreations described by two words? Find the prime ministers who were born in a state which has a name containing the character 'A'. Chapter 8 Review Questions 1. 2. 3. 4. 5. Where may arithmetic expressions occur in an SQL Select command? What arithmetic operators are available in SQL? List them in order of precedence. How can the column names in a result table be turned off in microSQL? Describe what happens when character items are concatenated. What symbol is used for the SQL concatenation operator? Exercises Write a Select command for each of the following: 1. List the current age of all prime ministers who are still alive.
  • 4. 2. 3. 4. 5. In which year did Harold Holt die? How many years ago was each prime minister married? List the ages of prime ministers who were alive in 1920. Order the result on descending values of age. List each Australian-born prime minister together with an appropriate message and his state of birth (use only one item in the Select clause of your query). Chapter 9 Review Questions 1. 2. 3. 4. 5. 6. Explain how aggregate and scalar functions differ. List the aggregate functions provided by microSQL. What rules must be followed when aggregate functions are used in a query? Describe the three ways in which the Count function may be used and state the meaning of the value returned in each case. List the scalar functions provided by microSQL. State the purpose of each. How many characters are normally returned when a number is converted to character? How may this be changed? 7. What determines whether the characters returned by the Cast function are left or right justified? What is a fill character and how is one specifed in the case of a right-justified result? 8. State the rules that apply to arguments used with the microSQL date functions. 9. List the date functions provided by microSQL and state the purpose of each. 10. How may a date in short or US short format be converted to a decimal date? Exercises Write Select commands for each of the following: 1. List the total, average, and standard deviation of the years served by prime ministers who represented New South Wales. 2. How many children have resulted from the marriages of all Australian prime ministers? 3. Find the number of times that different prime ministers have been commissioned. 4. Which prime minister who represented Victoria died at the greatest age? 5. How many years ago was Malcolm Fraser first commissioned as prime minister? 6. In how many ministries did John Gorton serve as prime minister? What were the numbers of his first and last ministries? 7. How many years is it since a prime minister who represented the Country party was commissioned? 8. List each prime minister's name together with the date(s) on which he was commissioned in the format mm-dd-yyyy. 9. Find the approximate number of years and months that each prime minister served. 10. How many more days would Malcolm Fraser have had to serve to complete his last year of service? 11. Calculate the number of days John Howard has served since first being commissioned as prime minister? 12. Find the interval in days between the dates of Gough Whitlam's first and last commissionings.
  • 5. 13. Write the select-expression which produced the following result table: Barton E died at age 71 Deakin A died at age 63 Watson J C died at age 74 14. For each prime minister who belonged to a party having two words in its name, list the names of the prime minister and party in the precise format indicated: Reid G H ( Free Trade ) Hughes W M ( National Labor ) Chapter 10 Questions Review 1. 2. 3. What is an unconstrained join? Explain what happens when an equijoin of two tables is performed. Define the term domain. Why should the join operation be restricted to tables which have column values drawn from a common domain? 4. What is an alias? How are aliases assigned to tables in a query? 5. Explain how a table can be joined to itself in SQL. 6. Define the terms inner join and natural join. 7. When is it necessary to specify an outer join? What types of outer join are available in SQL? 8. When would the using clause occur in a join? 9. What is the purpose of the on clause in an SQL join? 10. Describe the result table for a cross join and union join. Exercises Write Select commands for each of the following; use the SQL join operator in 3 to 6 inclusive: 1. 2. 3. 4. 5. 6. For each prime minister, list his name, the name of his spouse, and the party to which he belonged as prime minister. List the names of the prime minister and deputy prime minister for each ministry since federation. Display the name of each prime minister born in Victoria together with the names of his recorded recreations. For each prime minister, list his name and party. Include in the report the party to which he belonged, if any, as deputy prime minister. List the name, birth year, marriage year, recreations, and ministry numbers of the ministries in which he served, for all prime ministers who were born after 1900 and married before 1950. Order the result on ascending values of marriage year within birth year. Display in pairs the names of prime ministers who were married in the same year. Also include the marriage year in the result.
  • 6. Chapter 11 Review Questions 1. 2. 3. 4. 5. What is the effect of including a Group By clause in an SQL query? State the rules that must be followed when using grouping. Describe the difference between search conditions when used in Where and Having clauses. In what order are search conditions in Where and Having clauses applied when SQL executes a query? How are rows ordered by microSQL if a query contains a Group By clause but not an Order By clause? Exercises Write Select commands for the following queries: 1. 2. 3. 4. 5. 6. 7. 8. Find the average death age for prime ministers born in each state. How many deputy prime ministers have come from each party? How many different deputies have there been (from each party)? Including only prime ministers born in Australia, list the total number of prime ministers who represented each state. For each birth state, list the age of the prime minister who lived the longest. List the names of those prime ministers who had more marriages than they had children from all their marriages. Which parties have had more than two different prime ministers commissioned? List the result in descending order of number commissioned. List the prime ministers who married more than once, and had at least one child from each marriage. Which prime ministers who married more than once had at least one child from any of their marriages? Chapter 12 Review Questions 1. 2. 3. 4. 5. 6. State the rules for formulating subqueries in SQL. What are the differences between the result returned by a main query and that returned by a subquery? Explain how the any and all qualifiers are used to create set comparison operators in SQL. Which other set comparison operators are equivalent to in and not in? When may an ordinary comparison operator be used to test the result returned by a subquery? Distinguish between nested and multiple subqueries. Exercises Write Select commands containing subqueries for the following: 1. Find the name and age at death of the prime minister who died at the greatest age.
  • 7. 2. 3. 4. 5. 6. 7. 8. 9. List the names and years served for those prime ministers who were in office for more than the average number of years. Obtain full details of the marriage of the prime minister who was commissioned the most times. Which prime ministers also served as deputy prime minister? Find the name and state represented for those prime ministers who belonged to at least two different parties as deputy prime minister. List the name, birth state and year of birth for the Labor prime minister who had the maximum number of recorded recreations. Which prime minister had more than three children, represented New South Wales while belonging to the Labor party, and was deputy prime minister while a member of the United Australia party? Retrieve the name, birth state and years served for the prime ministers who married after 1950 and were commissioned at least twice. Find the state that has been represented by the most prime ministers. Chapter 13 Questions Review 1. 2. 3. 4. 5. Distinguish between correlated and noncorrelated subqueries. What is a correlation condition? A noncorrelated subquery is evaluated only once but a correlated subquery must be evaluated many times. Why? When is a condition that uses the exists operator satisfied? Why is it permissible to use an asterisk as the item to be selected in a subquery that follows exists? Exercises Use correlated subqueries in formulating Select commands for the following: 1. 2. 3. 4. 5. 6. Find the name, and age when first married, of those prime ministers who were married twice. Which prime ministers were commissioned before they were first married? For the Labor prime ministers who were commissioned more than once, find the year when they were commissioned for the second time. Which prime ministers were commissioned twice as many times as they were married? List the names of prime ministers who were first commissioned within twenty years of their (first) marriage. Find the number of times that a member of the Labor party has been deputy prime minister and prime minister in consecutive ministries. Use the exists operator in Exercises 7 - 10. 7. 8. 9. Which prime ministers also served as deputy prime minister? Find the names of prime ministers who had at least one of Bob Hawke's recreations. List the name and party of prime ministers who belonged to another party as deputy prime minister. 10. Which prime ministers were commissioned at least twice and served as deputy prime minister after they were first commissioned?