Skip to content
Advertisement

Tag: mysql

How to improve union query?

I have a query which is ‘working’ but slow and feels very poor and I don’t want to have to update each time we add/remove a supplier! Basically I have a table of ‘prices’ and for each suppler I need …

query with sql max function

table view with 4 records Would the following query work if I wanted to select the 2nd and 3rd records? Answer As your date values are not in well formatted, you need to first convert your values into DATE and then apply other logic. Please check my updated script now- Issues: You value in completion_date column is string. as a

Sum multiple columns in multiple rows

I have following data structure for sales: I need to know how many products with id=1 were sold for the last 12 month. If we are in June 2020 I need to sum M01, M02, M03, M04, M05 (WHERE year=2020) and M06, M07, M08, M09, M10, M11, M12 (WHERE year=2019) WHERE id=1. I should get a value of 36. Please,

How to fill the custom columns with joined values

I have a query like: I have 2 tables: sales_order_grid (where the main data is) sales_order_status_history (where I want to attach the status data) I need to fetch custom columns values of the latest statuses (I mean there could be more than one status for the order, but the date differs). Could you please help me with that? Answer I

Advertisement