I am trying to select results from the result of another select but I am getting an error. Below is the sql query. select reference,date, bdx_name, bdx_id, description, …
Iterating through users and check if they exist in the past 12 months
DB-Fiddle CREATE TABLE customers ( id SERIAL PRIMARY KEY, order_date DATE, customer VARCHAR(255) ); INSERT INTO customers (order_date, customer) VALUES (‘2020-04-10’, ‘user_01’), (‘2020-…
How to count distance between two lines in a SQL database?
Here is a sample of my database with 3 colums : class, year and student_name. I search the “distance” in terms of common student between two given student. (Like in the famous game “6 …
Adding customers name alongside customer name
based on the DB schema I am trying to get for each customer the Id, date, customer name and the customer. Can anyone help? I am struggling with adding the name of the customer. This is what I have …
How to drop a column with foreign key in MySQL?
Let’s say I used the following structure to create a table: CREATE TABLE staff ( sid INT AUTO_INCREMENT, sfname VARCHAR(30) NOT NULL, slname VARCHAR(30) NOT NULL, uid int UNIQUE, …
Query inserts more records than expected from a JSON file SQL Server
I am inserting data from a JSON file. In the JSON file, a key has 3 value items. The problem I have is that instead of inserting the 3 that it actually goes through with the cross aply, it inserts me …
Updating a column across the table going in loop, how do avoid?
Below update statement is running in a loop, how do i avoid this? I have 86Million rows in the table Table Data as below Desired table should be Thank you, Yum Answer Assuming that your query runs, you seem to need a where clause. I would speculate: Note that I removed gw from the group by. It is used as
SUM with Multiple Conditions
I’m writing a query on SQL Server and have hit a wall on cumulative sum with multiple conditions. I need to sum all the purchases in a day made by a user, I can do it separately, sum purchases by day(Daily_Total), or sum purchases by user(User_Total), but I run into a wall when I need both conditions me…
identifier ‘NEW.CITY_POPULATION’ must be declared
I am trying to declare a oracle trigger that will update the city name when the city population reaches 0 but I am getting this error. Answer If you’re going to reference the :new pseudo-record in a trigger body, it needs to be prefixed with a colon. A trigger on cities generally cannot query the cities…
Select rows where the title contains any term from a list
I have a datset that has product_id, product_url, email, product_title, etc. I want to pull rows where product_title contains certain adjectives (Fabulous, Stunning, Rare, Amazing, Unique, etc etc. ) from a list of 400+ words. How do I do this without doing a separate select function for each word? I am using…