Table:
Tree
Column Name Type id int p_id int id is the primary key column for this table. Each row of this table contains information about the id of a node and the id of its parent node in a tree. The given structure is always a valid tree.
Each node in the tree can be one of three types:
- “Leaf”: if the node is a leaf node.
- “Root”: if the node is the root of the tree.
- “Inner”: If the node is neither a leaf node nor a root node.
Write an SQL query to report the type of each node in the tree.
Return the result table ordered by
id
in ascending order.The query result format is in the following example.
Table:
Products
Column Name Type product_id int store1 int store2 int store3 int product_id is the primary key for this table. Each row in this table indicates the product’s price in 3 different stores: store1, store2, and store3. If the product is not available in a store, the price will be null in that store’s column.
Write an SQL query to rearrange the
Products
table so that each row has(product_id, store, price)
. If a product is not available in a store, do not include a row with thatproduct_id
andstore
combination in the result table.Return the result table in any order.
The query result format is in the following example.
Table:
Employees
Column Name Type employee_id int name varchar employee_id is the primary key for this table. Each row of this table indicates the name of the employee whose ID is employee_id.
Table:
Salaries
Column Name Type employee_id int salary int employee_id is the primary key for this table. Each row of this table indicates the salary of the employee whose ID is employee_id.
Write an SQL query to report the IDs of all the employees with missing information. The information of an employee is missing if:
- The employee’s name is missing, or
- The employee’s salary is missing.
Return the result table ordered by
employee_id
in ascending order.The query result format is in the following example.