So given the following example query I want to fetch all documents created in a range of two dates. As you can see I put some calculations into variables because I can reuse them in the WHERE clause. Further those calculations only differ by one value, the month at the end. So the calculation could also be Is…
Tag: mysql
How to select row values conditionally and change them to custom columns?
I have two tables orders, product_meta that are as follows: orders: order_id product_id 1 45 1 46 2 46 product_meta: product_id meta_key meta_value 45 price …
Adding a conditioned extra field to a query result
I have these two tables TABLE 1 ( tournaments_data ) tournament_id | accound_id | data1 | data2 TABLE 2 ( tournaments_subscriptions ) tournament_id | account_id Here, i have to read data of table 1 …
Combining MySQL Queries to get total amount
I’m trying to combine the following 2 queries. table_A stores a list of available appointments and number_open is how many open slots there are for a specific appointment, in this case 2020-06-30 AM which has 5 open. table_B contains any dates waiting to be accepted and has a different record for each d…
Grouping together results of multiple GROUP_CONCAT() with distinct values only
second attempt at this question with more detail. I am attempting to group the distinct values of multiple columns together for objects of the same name. I can use GROUP_CONCAT on each of the ‘Type’ columns, but I can’t merge them together to get a distinct set of values for each name Here i…
Getting values from the first row, last row, and an aggregation in MySQL Window function
For a marketing related analysis I need to provide data on the first- and last-touchpoint and of the number of total interactions with our website. A simplified version of our interaction table looks like this: Our current approach looks like this: Currently, we observe that the runtime scales approximately l…
Mysql Join, Count and Sum?
campaign table are the item for sale and on the transaction table are the item sold. I want to count the transaction_id that are made transaction table and sum the total of sold item.. but the table are different.. Here is what I tried: campaign table: transactions table: Answer To get the total payout for al…
MySQL UNION and like multiple table . #1064 Mysql
Thanks for reading my question. I am trying to connect the 3 columns of multiple tables together then find the nameProduct column that match LIKE request. All tables have different columns and look …
Count json tags in sql
I have this json strings And know i want the following output I wanted to do this with a sql query. If you know how to do this, thanks in advance! Answer If you’re not using MySQL 8, this is a bit more complicated. First you have to find a path to a name element that has the value phone
SQL Insert with Inner Join trying to insert into wrong column
I have an existing table of products, and I’m trying to insert new attributes from other tables into my main product table. Here’s my query: The error that I get is: Field ‘product_id’ doesn’t have a default value. I’m not trying to insert into the product_id column, I̵…