sql - Sum of Quantities by Member -
There was a custom field "member_name" created for the SQL statement for Word, which was created in order 3 in key = member_name Goes under. I need to create a report that shows the amount of SM (according to key = "_qty") according to member number
when the tables:
Order1 - order1_id, order3_id order2 - order2_id, key, value order3 - order3_id, key, value example:
order1 order1_id - order3_id 2 - 292 3 - 292 4 - 281 order2 order2_id - key - value 2 - '_qty' - 1 to 3 - '_qty' - 2 4 - '_qty' - 1 order3 order3_id - key - value 292 - 'MEMBER_NAME' - John 292 - 'MEMBER_NAME' - John 281 - 'MEMBER_NAME' - Bill Desired results:
P>
John 3 Bill 2 I am working with:
SELECT order3 .value, a.member_count (from order3 intermediate order3 (select value, sum (*) in value Order3.order3_id = order1.order1_id a) From order 2. Order3_id = order1.order1_id a) From order 2. Order2.value = '_ quantity' from MEMBER_COUNT order2 group as joining join order2 on Order2_id = order1.order1_id) by group a.member_count WHERE order3 .key = "member_name";
Try the following query first for each order3_id Total qty receives the value. Then, the name is seen above order3 table. DISTINCT o3.value, totals.total_qty select order3 O3 Insert from (o1.order3_id choose order3_id, order2 o2 from y2.value) interi total_qty order1 join o1 On o2.order2_id = o1.order1_id and o2.key = '_qty' o1.order3_id on group) yo3.order3_id = totals.order3_id and o3.key = 'member name'; You can group in Order 3 table with only the name. However, if 2 order 3_id has the same name, you will get unexpected results.
Comments
Post a Comment