I have table in MySQL with times spent by customers and I need to find the most busy 30 mins. Expected result is something like multiplerows with time and number of customers: I can easily make 5 sql queries and get the result (I made some view in similar problem https://stackoverflow.com/a/59478411/11078894 …
Tag: mysql
SQL query to find largest id for each user_id
I am currently querying from 4 different tables, users, memberships_users, membership_levels, phone_area_code From the users table, I would like to select id user_login, user_email, display_name …
How can I group data from multiple rows into the same row?
I have a query: That returns I want to combine the rows and take one value from each column (doesn’t matter which, first, last, can be any) So one elementary school, one high school, one university. It would look like: However, when I try to group by: I’m getting only a value for one of the column…
Count of line item in MySQL
I have a complex query joined to multiple tables to show a “transaction history”, I want a quick and easy way to count the occurrences of order_id to make it as the line_number. I had it done with code but for performance reason I want to have it done with MySQL. Here is an example of what I have:…
Ranking subcategories while keeping order of ID
I have the following table: I would like to rank the subcategory (cat2). Desired outcome: I use DENSE_RANK with PARTITION BY to get the following result: Statement: As you can see, the only thing I’m missing is the order of the result. Currently, the rank is based on the alphabetic order of cat2. Howeve…
SQL:pivot: convert each row into many rows depends on a condition
I have been trying to solve this but could not figure it out. so this is the table and more columns could be added: So if the value is one then I will display it in a different row but with the value being the column header itself My boss suggested using pivot to solve this but I am open
MySQL Query with distinct on a column value
I have this table (with 100k+ rows): room_id | emote_id | count | since —————————————- 1 | 22 | 718| 1577135778 1 | 23 | 124| 1577135178 …
#1005 – Can’t create table `musicplayer`.`Albums` (errno: 150 “Foreign key constraint is incorrectly formed”)
I’m trying to define some tables with SQL, but when I execute it I have an error. Below there is my code and the error which I receive. CREATE TABLE Artists ( id INT AUTO_INCREMENT PRIMARY …
How to add parameters to a query when query is unknown length
I am working on a project where multiple rows are needed to be added to a MySQL table, due to the high latency of the connection I am trying to add all the values in one command to save time. So far I have a SQL query that is determined by a string array(each string being a “token”), this, being
How to JOIN postmeta table and get the posts before the date of custom field using SQL
I’d like to combine wp_posts table and wp_postmeta table and get the posts before the date of custom field. Code with only wp_posts table is below and it works fine I want to add “postmeta table” to “post table” and get only posts before the date of custom field if it is “W…