大家好,向大家致以热烈的问候,我在 posgresql 中编写复杂的查询时遇到了一些挑战。事实是我在编写此特定查询期间时遇到问题,非常需要您的帮助。让我们开始吧。
这是我的桌子
[products_tb] [client_tb] [sales_tb]
+--------------+ +-------------+ +-------------+--------------+-----+
| product_name | | client_name | | client_name | product_name | qty |
+--------------+ +-------------+ +-------------+--------------+-----+
| shoe | | john | | john | shoe | 20 |
+--------------+ +-------------+ +-------------+--------------+-----+
| belt | | bob | | john | belt | 9 |
+--------------+ +-------------+ +-------------+--------------+-----+
| kim | | bob | shoe | 2 |
+-------------+ +-------------+--------------+-----+
| bob | belt | 98 |
+-------------+--------------+-----+
| kim | shoe | 46 |
+-------------+--------------+-----+
| kim | belt | 3 |
+-------------+--------------+-----+
[query output] # this output will be displayed using php and html
+----------+-------+------+-----+-----+
| products | Total | john | bob | kim |
+----------+-------+------+-----+-----+
| shoe | 68 | 20 | 2 | 46 |
+----------+-------+------+-----+-----+
| belt | 110 | 9 | 98 | 3 |
+----------+-------+------+-----+-----+
我正在尝试编写一个允许我生成表 [查询输出] 的查询。任何帮助都感激不尽。
非常感谢。