edit: version 8.0.20 I’m learning sql just now, I try to fix it but I’m not able to do it. I have 3 table This is an easier scheme but it’s enough. The return_date must be less than delivery_date + 30 days I tried to use a check on return_date but no work, so I created a view to select
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” instead of a “correlated subquery” “Correlated subqueries”
How do I create cohorts of users from month of first order, then count information about those orders in SQL?
I’m trying to use SQL to: Create user cohorts by the month of their first order Sum the total of all the order amounts bought by that cohort all-time Output the cohort name (its month), the cohort size (total users who made first purchase in that month), total_revenue (all order revenue from the users in that cohort), and avg_revenue (the
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
MS SQL Server Date Month Output
SQL will output a month part as a number but I’d like to out put the 3 char version (Jan, Feb, Mar etc) My query thus far is Answer For each DBMS the way is different Here are few 4 DBMS’s MS SQL Server MySQL Postgresql Oracle So in your case use the appropriate date field instead of current date
SQL Case Order By specific order and Direction
I have a table that I need sorted on fields By @SortBy and @SortDirection, for ID,PriorityID,stateType (column type is int) result is OK, but for Title (nvarchar) Query Result is: Conversion failed when converting the nvarchar value ‘Title Column value’ to data type int. Query: Answer The types are different, and that is a problem for the case expressions. The
Need Help Generating NULL Entries for Months with No Orders
I have to create output that shows all fields from a table (Tbl) and create an additional column that calculates Cumulative Sum for each customer by month, (eg if a customer has two sales in April, the new column will have the Sum of those sales and any prior sales on both rows). That much I can do. My issue
What is difference between `flag is TRUE` vs `flag = TRUE` in MySQL?
I ran the following queries in MySQL – Time taken = 1 second. vs Time taken = 66 ms. I have indexes on (valid, priority) and (valid). Why is there such a huge difference? What is the difference between Is TRUE vs = TRUE ? Answer As per the Mysql Doc for IS operator IS boolean_value Tests a value against
SQL get Values where some is greater than value with Having not working
I have this code: But it gives me an error. I can not figure it out. Happy for every help! Answer Having clause execute after group by and then select so you have to use aggregated function with having as following
Mariadb 10.4 Data truncated for column ‘column_name’ on insert but not on update
I have the following table (mariadb 10.4) called p: I currently have a couple of million rows on this table with the sources a, b, c, and d. Just recently we applied a migration to add source_e and we started getting the error ERROR 1265 (01000): Data truncated for column ‘source’ at row 1 when trying to inset a row