Create the following table in your database with the following schema: Table: Users I Column Name 1 Туре | id | name | int | varchar | +-- ---------+ id is the primary key for this table. name is the name of the user. Table: Rides | Column Name 1 Туре | id | user_id I distance | int | int | int +---- id is the primary key for this table. user_id is the id of the user who traveled the distance "distance". Add the following data to your tables: Input: Users table: +----- | id | name ---- | 1 | 2 | 3 | 4 | Alice | Bob | Alex | Donald | Lee | JonathanI | Elvis | 13 | 19 +----- Rides table: +------+ | id | user_id | distance | +---- | 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 120 | 317 | 222 | 100 | 312 | 50 | 120 | 400 | 230 | 13 | 19 | 8 | 9 | 19 | 7

A Guide to SQL
9th Edition
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Philip J. Pratt
Chapter7: Database Administration
Section: Chapter Questions
Problem 4SCG: Write, but do not execute, the commands to grant the following privileges: a. User Oliver must be...
icon
Related questions
icon
Concept explainers
Question

Show all the sql query codes and the output with it please

Create the following table in your database with the following schema:
Table: Users
| Column Name
| Туре
+-
+-
| int
| varchar |
| id
| name
+-
id is the primary key for this
table.
name is the name of the user.
Table: Rides
| Column Name
| туре
+-
| id
| user id
| distance
| int
| int
| int
+-
id is the primary key for this
table.
user id is the id of the user who traveled the distance "distance".
Add the following data to your tables:
Input:
Users table:
+------+
| id
| name
+-
| 1
| 2
| 3
| 4
| 7
| 13
| 19
| Alice
| Bob
| Alex
| Donald
| Lee
| Jonathan
| Elvis
+----
Rides table:
+------
| id
I user id
| distance |
+-----
+---
| 1
| 2
| 3
| 4
| 5
| 1
| 2
| 3
| 7
| 13
| 19
| 120
| 317
| 222
| 100
| 312
50
| 120
| 400
| 230
| 8
| 19
+-----
Transcribed Image Text:Create the following table in your database with the following schema: Table: Users | Column Name | Туре +- +- | int | varchar | | id | name +- id is the primary key for this table. name is the name of the user. Table: Rides | Column Name | туре +- | id | user id | distance | int | int | int +- id is the primary key for this table. user id is the id of the user who traveled the distance "distance". Add the following data to your tables: Input: Users table: +------+ | id | name +- | 1 | 2 | 3 | 4 | 7 | 13 | 19 | Alice | Bob | Alex | Donald | Lee | Jonathan | Elvis +---- Rides table: +------ | id I user id | distance | +----- +--- | 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 7 | 13 | 19 | 120 | 317 | 222 | 100 | 312 50 | 120 | 400 | 230 | 8 | 19 +-----
Return the result table ordered by travelled_distance in descending order, if two or more users traveled
the same distance, order them by their name in ascending order.
Hint: Use IFNULL(a,b) function in your select clause where a is the value that should be returned and
b is the value that should be returned if a is NULL.
The result should be:
Output:
| name
travelled distance
+--
| Elvis
| Lee
| Bob
| Jonathan | 312
| Alex
| Alice
| Donald
| 450
| 450
| 317
| 222
| 120
+-
Explanation:
Elvis and Lee traveled 450 miles, Elvis is the top traveler as his name is
alphabetically smaller than Lee.
Bob, Jonathan, Alex, and Alice have only one ride and we just order them by the
total distances of the ride.
Donald did not have any rides, the distance traveled by him is 0.
Transcribed Image Text:Return the result table ordered by travelled_distance in descending order, if two or more users traveled the same distance, order them by their name in ascending order. Hint: Use IFNULL(a,b) function in your select clause where a is the value that should be returned and b is the value that should be returned if a is NULL. The result should be: Output: | name travelled distance +-- | Elvis | Lee | Bob | Jonathan | 312 | Alex | Alice | Donald | 450 | 450 | 317 | 222 | 120 +- Explanation: Elvis and Lee traveled 450 miles, Elvis is the top traveler as his name is alphabetically smaller than Lee. Bob, Jonathan, Alex, and Alice have only one ride and we just order them by the total distances of the ride. Donald did not have any rides, the distance traveled by him is 0.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Query Syntax
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
A Guide to SQL
A Guide to SQL
Computer Science
ISBN:
9781111527273
Author:
Philip J. Pratt
Publisher:
Course Technology Ptr
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning