I would like to generate Magento native report as follows:
Can anybody provide the SQL query for above table ?
- Column Name CustomerGender = customer attribute
- Column Name Group = Customer Group native feature
- Grand Total = Grand total from Sales order table
Went through plenty of the links but got regular simple joins.
asked Dec 29, 2019 at 16:16
Softec
2,1232 gold badges13 silver badges32 bronze badges
-
Can you try the query and let me know it's perfect for you!Vithal Bariya– Vithal Bariya2019年12月30日 05:05:31 +00:00Commented Dec 30, 2019 at 5:05
-
Have you tried my code?Vithal Bariya– Vithal Bariya2019年12月30日 05:56:48 +00:00Commented Dec 30, 2019 at 5:56
-
let me give a try..!!!Softec– Softec2019年12月30日 14:18:36 +00:00Commented Dec 30, 2019 at 14:18
-
thank for the answer.. i'm able to get the with the result.Softec– Softec2019年12月30日 14:59:19 +00:00Commented Dec 30, 2019 at 14:59
2 Answers 2
Can you try this Query
SELECT
eav_attribute_option_value.value AS 'Customer gender',
customer_group.customer_group_code AS 'Group',
CONCAT('$',
FORMAT(SUM(sales_order.`grand_total`),
2)) AS 'Grand total'
FROM
`customer_entity`
LEFT JOIN
sales_order ON customer_entity.entity_id = sales_order.customer_id
LEFT JOIN
customer_group ON customer_entity.group_id = customer_group.customer_group_id
LEFT JOIN
eav_attribute_option_value ON customer_entity.gender = eav_attribute_option_value.option_id
GROUP BY customer_entity.entity_id
ORDER BY SUM(sales_order.`grand_total`) ASC
The final output is enter image description here
answered Dec 30, 2019 at 4:44
Vithal Bariya
8737 silver badges21 bronze badges
-
Error in query (1055): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'magento2db.eav_attribute_option_value.value' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_bySoftec– Softec2019年12月30日 14:51:23 +00:00Commented Dec 30, 2019 at 14:51
I managed to get the results using below SQL query.
SELECT eav_attribute_option_value.value as 'Gender',
customer_group.customer_group_code as 'Group',
CONCAT('$', FORMAT(SUM(sales_order.`grand_total`),2)) AS 'Grand total'
FROM `customer_grid_flat`
LEFT JOIN
customer_group ON customer_grid_flat.group_id = customer_group.customer_group_id
LEFT JOIN
sales_order ON customer_grid_flat.entity_id = sales_order.customer_id
LEFT JOIN
eav_attribute_option_value ON customer_grid_flat.gender = eav_attribute_option_value.option_id
WHERE eav_attribute_option_value.value IS NOT NULL
GROUP BY eav_attribute_option_value.value, customer_group_code
answered Dec 30, 2019 at 15:03
Softec
2,1232 gold badges13 silver badges32 bronze badges
Explore related questions
See similar questions with these tags.
default