Skip to content

Tag: mysql

Optimize Query Mysql to count data in each district

i have this query for calculate success total in each district. this query works but its take until 2min to output data, i have 15k rows in orders. the output should be like this can you help me to improve the peformance? Thanks Answer Try performing the grouping/calculation in a joined “derived table&#…

How to list data from join table in one row?

There 3 entities: 1) Question, 2) Tag and join table between them – question_has_tag. When I make a select query like: I’m getting the following result: and I needed to get: How to get it ? Answer You need to GROUP them and use GROUP_CONCAT Like

MySQL Running Total By Group, Time Interval

I would like to take a table of customer orders like this: And create a table calculating a cumulative running total by week, segmenting the weeks by 7 days starting at the earliest date (2020-03-01, 2020-03-08, etc.). Something like: Thanks for the help! Answer You can use aggregation and window functions (t…

Subtract scanner value from sql table value

I’m trying to subtract a scanner input from a table value. Here’s a screenshot of my table: Here’s what my code looks like: The output of my code is: Here’s what I want my table to look like after subtracting 100 (my scanner input quantity): I’m unsure as to why subtracting my sc…