Question
This is a tricky problem designed to help you think out of the box on the use of declarative database programming for solving problems. SQL
This is a tricky problem designed to help you think out of the box on the use of declarative database programming for solving problems. SQL is pretty good about letting you do cross products to get all possible pairs (x, y) from two sets of elements with a simple query, for example: SELECT x, y FROM BigX, BigY; But sometimes you would like to do this sort of thing horizontally instead of vertically. A permutation is an ordered arrangement of elements of a set. For example, if we have the set {1, 2, 3}, the permutations of those elements are (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), and (3, 2, 1). The rule is that for (n) elements, you have a factorial number (n!) of permutations. What we would like is a SQL query that returns one permutation per row from a set of the first seven integers (that will give us 5,040 rows). Assume you are given the following table Elements: CREATE TABLE Elements (i INTEGER PRIMARY KEY); INSERT INTO Elements VALUES (1), (2), (3), (4), (5), (6), (7); Q1. Write down your SQL query. Hint: Maybe you can use some NOT INs. Q2. The solution you get for the problem when you use an SQL interpreter and RDBMS to solve this problem (e.g. you can use SQLite) i.e. run the create table/insert statements and then your SQL query from Q5.1 above. Copy-paste only the first 10 rows you get in the output. Note: The SQL query may be quite long so you may find it useful to create the query in a text file and use the source command (or equivalent) in your SQL interpreter to readin and execute the query.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started