我正在使用小项目进行销售我的一些表格
sale_order
+----+------------+--------+--------------+-------------+----------+----------+
| so | date | po_num | structure_id | customer_id | quantity | rate |
+----+------------+--------+--------------+-------------+----------+----------+
| 2 | 2015-01-09 | 23 | 1 | 11 | 1234 | 0.0000 |
| 3 | 2015-09-02 | 1234 | 1 | 12 | 1000 | 0.0000 |
| 12 | 2015-09-01 | 1234 | 3 | 12 | 100000 | 12.0000 |
| 13 | 2015-09-01 | 232 | 4 | 11 | 1000 | 123.0000 |
| 14 | 2015-09-01 | 1212 | 4 | 12 | 10000 | 123.0000 |
| 15 | 2015-11-04 | 3424 | 1 | 11 | 2555 | 0.0000 |
| 16 | 2015-11-04 | 343 | 2 | 11 | 233333 | 0.0000 |
| 17 | 2015-12-02 | 12345 | 3 | 13 | 10000 | 0.0000 |
+----+------------+--------+--------------+-------------+----------+----------+
结构
+----+------------------+
| id | job_name |
+----+------------------+
| 4 | ketchup |
| 3 | bubble |
| 2 | masala |
| 1 | xyz |
+----+------------------+
客户
+-------------+-------------------------------+
| customer_id | customer_name |
+-------------+-------------------------------+
| 11 | customer 1 |
| 12 | xyz |
| 13 | abc |
+-------------+-------------------------------+
调度
+----+----+------------+-----------+
| id | so | date | delivered |
+----+----+------------+-----------+
| 1 | 2 | 2015-09-02 | 123.00 |
| 2 | 12 | 2015-09-02 | 203.00 |
| 3 | 12 | 2015-09-17 | 213.00 |
| 4 | 2 | 2015-05-11 | 123.00 |
| 5 | 14 | 2015-11-06 | 233.00 |
+----+----+------------+-----------+
我要创建一份报告,显示总订单数量以及相关的交货和余额。用PHP C#等编程语言我可以用两次请求mysql服务器第一次获取命令
SELECT
so.po_num,
so.date,
c.customer_name,
st.job_name,
so.rate,
so.quantity
FROM
sale_order AS so
JOIN
structure AS st ON so.structure_id = st.id
JOIN
customer AS c ON so.customer_id = c.customer_id
然后用这个id到达那里交付
SELECT
d.date,
d.id AS reference,
d.net_weight AS deliverd
FROM
dispatch AS d
WHERE
d.so = so.id
但是我希望用一个单一的查询来生成所有东西,无论如何都要用mysql查询直接实现这个结果
期望的结果,有或没有 -
SO # | DATE | JOB NAME | RATE | ORDER QUANTITY | D DATE | REFREENCE | D QUANTITY | BALANCE
1 2/2/2015 ABC XXX XXX 4/2/2015 D-12 XX XX
- - - - - 5/2/2015 D-22 XX XX
- - - - - 7/2/2015 D-50 XX XX
2 2/2/2015 ABC XXX XXX 4/2/2015 D-14 XX XX
- - - - - 5/2/2015 D-26 XX XX
- - - - - 7/2/2015 D-58 XX XX
提前致谢
答案 0 :(得分:0)
@humaira我认为在单个查询中无法完成所有操作。可能你要分两部分写。