I want to check for keys in my json datatype, where the key is the number of a week. Basically, I use this function to get the number of the next week: extract(week FROM current_date) + 1 Now I want to use the returned value, to check whether this key exists in my object and if not return an empty
MYSQL getting data from three tables
I am trying to find the drinker and total amount of money spent on drinks for all drinkers in February 2020. I also need to include drinkers who haven’t ordered a drink in this period. Here are the three tables: Here is my statement so far: I am very new to SQL, I know that there are a number of
Calculating average time (in days) between customer first and second order on BigQuery
I’m trying to figure out the avg days it takes for a customer to repeat purchase. Here is what I have It’s returning this I want to now get the average days between all first and second purchases, then second and third et Sample data set |———————|—&#…
Laravel Query Builder joining with alias
I have two tables Unknown table Clients table My Code : Joining will be with the clients.id => unknown.parent_id… As because the clients table has a parent_id that’s why i have to use the alias Please Help me to do so! Answer Using Alias Working Solution:
SUBSTR in oracle not working when there is line break in the string
Okay so I am working with a database that has data in many formats. I was asked to split a string into 3 columns by 150 length in each column The data in the table is stored as this I want to split this data into 3 columns , COL1, COL2, COL3 When I use this query it works fine.
Amazon RDS – Postgres not using index for SELECT queries
I have a feeling I am doing something terribly wrong but I can’t seem to figure it out. I have the following query which I am trying to execute: Also, I have an index on day, month, year which I had set up using the following command Now I figured the setting to set sequential scan on/off and tried play…
Set prefix in SQL CASE expression
I have problem setting a prefix in a case statement. Data set: When I run this query my result is this: Desired result is this: As one can see, the first zero is not shown in the result. How can I achieve this? Answer CASE expression would always return one type so, you need to do conversion:
Save value from last year in current table
This is a more general question about database designing. I am currently migrating an Excel/VBA program to SQL and got following situation where i need food for thought, as i am doing this the first …
Postgres pattern matching middle letters of a string
How would I match a name, such that one of the middle letters of the name must come from the word ‘qwerty'(thus containing either of the letters ‘q’, ‘w’ , ‘e’, ‘r’, ‘t’,’y’)? I am curious how you can determine what the middle lette…
Removing backslashes when using Oracle’s JSON_ARRAY function?
How do you get rid of the back slashes, but still keep the double quotes when using json_array? TABLE A: Wrong code: Wrong output: Desired output: And yes, I know you can just concatenate like so “select ‘[‘|| etc. without using the json_array, but I need to have that in the code. Is there a…