|
Question : Retruning a count with GROUP_CONCAT
|
|
Hi, The last line in my SELECT 'SE*',GROUP_CONCAT COUNT(*) (op.orders_products_id),'*', o.orders_id, '~' errors out. My previous GROUP_CONCAT works perfectly. What I'm trying to do with the second GROUP_CONCAT is return the number of rows the first GROUP_CONCAT generated by running the GROUP_CONCAT again and just count the rows, but it seems I'm a bit mixed up. Any input would be appreciated. Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
|
/* create ST 850 PO for each order */
SELECT CONCAT('ST*850*', o.orders_id, '~',
'BEG*00*SA*', o.orders_id, '**', CURDATE( ) +0, '~',
'N1*BT*SuperStore~',
'N3*4225 Spooner BLVD~',
'N4*Wineville*CA*92056~',
'N1*ST*', o.delivery_name, '~',
'N3*', o.delivery_street_address, '~',
'N4*', o.delivery_city, '*', o.delivery_state, '*', `delivery_postcode` , '~',
GROUP_CONCAT(CONCAT(
'PO1*',op.orders_products_id, '*', op.products_quantity, '*EA**VN*', op.products_model, '~',
'PID*F****', op.products_name) SEPARATOR '~') , '~',
'CTT*3*****~',
'SE*',GROUP_CONCAT COUNT(*) (op.orders_products_id),'*', o.orders_id, '~'
)
FROM orders o
INNER JOIN orders_products op ON op.orders_id = o.orders_id
WHERE o.orders_status = 5 AND o.isa_id = 0
GROUP BY o.orders_id; /* May need to add OrderBy */
|
|
Answer : Retruning a count with GROUP_CONCAT
|
|
I would do that with a sub query.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
|
/* create ST 850 PO for each order */
SELECT CONCAT('ST*850*', o.orders_id, '~',
'BEG*00*SA*', o.orders_id, '**', CURDATE( ) +0, '~',
'N1*BT*SuperStore~',
'N3*4225 Spooner BLVD~',
'N4*Wineville*CA*92056~',
'N1*ST*', o.delivery_name, '~',
'N3*', o.delivery_street_address, '~',
'N4*', o.delivery_city, '*', o.delivery_state, '*', `delivery_postcode` , '~',
GROUP_CONCAT(CONCAT(
'PO1*',op.orders_products_id, '*', op.products_quantity, '*EA**VN*', op.products_model, '~',
'PID*F****', op.products_name) SEPARATOR '~') , '~',
'CTT*3*****~',
'SE*', (select count(*) from orders_products p where p.orders_id = o.orders_id ),'*', o.orders_id, '~'
)
FROM orders o
INNER JOIN orders_products op ON op.orders_id = o.orders_id
WHERE o.orders_status = 5 AND o.isa_id = 0
GROUP BY o.orders_id; /* May need to add OrderBy */
|
|
|
|
|