我需要一个包含计数数据的表。
我有2个基表,3个连接表有数据。
SELECT * FROM job_action
id action_code action_name price category ...
1 2563 printing 25 SZ
2 5236 graphic 20 NY
3 6325 folding 19 CT
4 8996 sticking 5 KO
5 8956 booking 52 EL
6 2535 promo 2 SZ
...
和客户:
SELECT * FROM customers
id name code category ...
1 D, John 0042 A
2 D, Jane 0045 P
3 S, Tom 0065 K
4 F, Frank 0086 K
5 E, Goal 0120 P
数据表:
SELECT * FROM orders
id orderNum customer_name customer_code ...
1 15/653 D, John 0042
2 15/654 F, Frank 0086
…
工作:
SELECT * FROM jobs
id order_id jobName …
1 2 Flyer
2 98 Molino
3 132 Infographic
…
job_action_items:
SELECT * FROM job_act_items
id job_id item_code category …
1 1 2563 SZ
2 1 2563 SZ
3 2 8996 KO
4 3 6325 CT
其中:
customers >———>> orders WHERE orders.customer_name = customer.name AND orders.customer_code = customer.code
orders >———>> jobs WHERE jobs.order_id = orders.id
jobs >———>> job_act_items WHERE job_act_items.job_id = jobs.id
我喜欢输出表:
cust.cat.| SZ | EL | CT | NY | KO | Total // job_action.category
A | 1 | 2 | 4 | 2 | 1 | 10 // count of element SZ cat. job_action of A cat. customer
P | 4 | 6 | 4 | 3 | 2 | 19
K | 5 | 3 | 5 | 0 | 0 | 13
我正在尝试一些INNER JOIN
查询,总结案例子查询和数据透视查询,但我不申请周期,这个数据库是基于os软件的,我需要一个数据来存储这些数据
在我看来,我对此非常愚蠢:(
请帮帮我! 谢谢,对不起我糟糕的英语!