想要显示来自不同表的查询结果:
Confirmed Orders: Confirmed Order Details:
+-------+--------+-------+ +--------+------+-------+------+
|COID |Customer|Payment| | CODID| COID | Items | Qty |
+-------+--------+-------+ +--------+------+-------+------+
| 1 | Jack | 11000 | | A | 1| Crack | 5 |
| 2 | Jill | 3000 | | B | 2| Weed | 7 |
+-------+--------+-------+ | C | 2| Beer | 7 |
+--------+------+-------+------+
Purchase Orders:
+--------+----------+---------+
| POID | PO Amount| Vendor |
+--------+----------+---------+
| 6 | 100 | Puffy.D |
| 7 | 500 | Bud Wise|
+--------+----------+---------+
并基于名为“DataMatrix”的表中的值:
DataMatrix:
+--------+--------------------+---------+--------------------------+
| DataID | table1 | DataID2 | table2 |
+--------+--------------------+---------+--------------------------+
| 1 | Confirmed Orders | A | Confirmed Order Details |
| 6 | Purchase Orders | A | Confirmed Order Details |
| 6 | Purchase Orders | 1T | Tracking |
| 2 | Confirmed Orders | B | Confirmed Order Details |
| 2 | Confirmed Orders | C | Confirmed Order Details |
| 7 | Purchase Orders | B | Confirmed Order Details |
| 7 | Purchase Orders | C | Confirmed Order Details |
| 7 | Purchase Orders | 2T | Tracking |
| 7 | Purchase Orders | 3T | Tracking |
+--------+--------------------+---------+--------------------------+
希望结果显示在一个表中,如下图所示:
+--------+------+-------+-------+--------+-------+--------+----------+---------+
| CODID| COID | Items | Qty |Customer|Payment| POID | PO Amount| Vendor |
+--------+------+-------+-------+--------+-------+--------+----------+---------+
| A | 1| Crack | 5 | Jack | 11000 | 6 | 100 | Puffy.D
| B | 2| Weed | 7 | Jill | 3000 | 7 | 500 | Bud Wise|
| C | 2| Beer | 7 | Jill | 3000 | 7 | 500 | Bud Wise|
+--------+------+-------+-------+--------+-------+--------+----------+---------+
自学成才的MySQL,主要从StackOverflow学习。我试过了
max(case when (criteria) then...etc.
但结果只能显示在一列中?我正在寻求甚至可以使用MySQL吗?