Jump to content

Is this query possible? Please help


mehere

Recommended Posts

Hello,

could someone please give me some help on how to set a DB query in SQL Manager from BO?

I am in need of something like:

IF Voucher field is not empty THEN for Orders placed from (date) to (date) whose status is delivered (possibly), get Order ID,Voucher id,voucher name,Customer name,Total products (tax incl.),Total products (tax excl.),total discounts,shipping,total paid.

Any help/hint would be much appreciated,

thank you very much!

Michele

Link to comment
Share on other sites

Here is a script that shows you all the columns.

Change c.current_state = 5 OR e.id_order_state = 5 to your delivered id state !!!

SELECT a.*, b.*, c.*, d.*, e.* FROM ps_order_cart_rule a
LEFT JOIN  ps_cart_rule b ON (a.id_cart_rule = b.id_cart_rule)
LEFT JOIN  ps_orders c ON (a.id_order = c.id_order)
LEFT JOIN  ps_customer d ON (c.id_customer = d.id_customer)
LEFT JOIN ps_order_history e ON (c.id_order = e.id_order)
WHERE c.current_state = 5 OR e.id_order_state = 5
GROUP BY a.id_order, c.id_order
ORDER BY a.id_order 

 

Edited by Guest (see edit history)
Link to comment
Share on other sites

Ok for other dummies like me, here's something to get all info starting from a specific cart rule ID for the whole year 2020 (invoiced orders):

SELECT * FROM ps_order_cart_rule a
LEFT JOIN  ps_cart_rule b ON (a.id_cart_rule = b.id_cart_rule)
LEFT JOIN  ps_orders c ON (a.id_order = c.id_order)
LEFT JOIN  ps_customer d ON (c.id_customer = d.id_customer)
LEFT JOIN ps_order_history e ON (c.id_order = e.id_order)
WHERE a.id_cart_rule = 810 AND (c.invoice_date BETWEEN '2020-01-01' AND '2020-12-31') AND (c.current_state = 5 OR e.id_order_state = 5)
GROUP BY a.id_order, c.id_order
ORDER BY a.id_order

More love to Tengler!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...