我有两个查询在三表中的其他问题mysql的结合了两种查询
表1 = hirarchey价格的用户
+----------+------------+-----------+
| userid | parent | price |
+----------+------------+------------
| 1 | null | 20 |
| 2 | 1 | 20 |
| 3 | 1 | 20 |
| 4 | 2 | 20 |
| 5 | 2 | 20 |
| 6 | 3 | 20 |
| 7 | 4 | 20 |
+----------+------------+-----------+
我需要得到与父母1中的所有用户ID,然后得到后裔在其他表和组通过用户ID和价格
+-------------+---------------+-------------+
| ancestor_id | descendant_id | path_length |
+-------------+---------------+-------------+
| 1 | 1 | 0 |
| 1 | 2 | 1 |
| 1 | 3 | 1 |
| 1 | 4 | 2 |
| 1 | 5 | 2 |
| 1 | 6 | 2 |
| 1 | 7 | 3 |
| 2 | 2 | 0 |
| 2 | 4 | 1 |
| 2 | 5 | 1 |
| 2 | 7 | 2 |
| 3 | 3 | 0 |
| 3 | 6 | 1 |
| 4 | 4 | 0 |
| 4 | 7 | 1 |
| 5 | 5 | 0 |
| 6 | 6 | 0 |
| 7 | 7 | 0 |
+-------------+---------------+-------------+
这http://sqlfiddle.com/#!9/9415ed/30做工精细为死者
价格的总和也有另一个表计算结果上一个查询的排名
http://sqlfiddle.com/#!9/b5de18/1
我需要合并两个查询非常感谢
在这个环节有关第二个查询更多信息compare result with other table mysql
2查询结果工作正常,但第二个查询读取表user_buys,我会user_buys删除并从第一个查询获得
请在这里发表你的表格定义。 SQL小提琴是好的,但它应该是一个补充。 – sagi
请检查此链接http://stackoverflow.com/questions/37875133/compare-result-with-other-table-mysql –
结果应该是什么样子? – Philipp