I have the following two tables in SQLite:
transactions:
| ID | Department |
| ------------ | ------------ |
| 1 | IT |
| 2 | Customer Service |
| 3 | Cleaning |
standards:
| IT | Customer Service | Cleaning |
| ------------ | ------------ | ------------ |
| 9.12 | 17.8 | 24.86 |
I want to join these two tables so the numbers in the second table become rows in my first table based on the matching value in the second table. The resulting table would look like this:
| ID | Department | Standard |
| ------------ | ------------ | ------------ |
| 1 | IT | 9.12 |
| 2 | Customer Service | 17.8 |
| 3 | Cleaning | 24.86 |
How can I join these, as I'm using the rows of one table and the columns of another?
1条答案
按热度按时间nfg76nw01#
您需要表的
CROSS
连接和CASE
表达式来选择适当的标准:请参见demo。