Here is a table FRUITS – FILTER A B C Apple 0 3 6 Orange 1 4 7 Apricot 2 5 8 Is it possible to create a function that returns column A for apple (0), B for Orange(4) and C for …
Is there a way to write an insert statement with string_split which ignores duplicates?
I am trying to insert rows into a table using string_split command. It works fine if there are no duplicates. However, if there are duplicates, it errors out. I would like to know how to modify the …
Postgres check constraint in text array for the validity of the values
I want to create something similar to this CHECK (ALL(scopes) IN (‘read’, ‘write’, ‘delete’, ‘update’)) scopes here is a field in the table which is text[] and I want to be sure that all the values …
Sum where values are equal between rows in certain columns in Oracle
With a query like the following: SELECT TBL.ID, TBL.CODE1, TBL.CODE2, TBL.CODE3, TBL.CODE4, TBL.QTY FROM DB.TBL TBL GROUP BY TBL.ID, TBL.CODE1, TBL.CODE2, TBL.CODE3, TBL.CODE4, TBL.QTY That returns …
Join query with null values
I have this query SELECT * FROM orders, products, suppliers WHERE product_id=products.id AND `geleverd` = 1 AND supplier_id=suppliers.id It works fine except that when the suppliers_id is …
Can you join by columns with aggregate functions?
Is it possible to join by aggregate functions? Let’s say we have in the main query: Select MIN(id) as MINID, product AS PRODUCT, SUB.produkt_name, SUB.product_type FROM log_table GROUP BY PRODUCT, …
Min and max with conditions in single sql query
I have a table like create table appointments ( id serial not null constraint appointments_pkey primary key, patient_id varchar(255) …
How to Join three tables properly
The main table has 4 columns: User Activity Table userActivityId userId therapistId activityId 1 1 1 1 Each of these columns is a table and these values are all …
check if row exists with specific value
I have 2 tables task and taskattributes. There is a linking between 2 tables with taskid. Each taskid has multiple attributes represented by key,value. I would like to find out if specific key exists …
Avoid NULL value in CASE SQL SERVER
How to avoid NULL values in CASE and SUM by P.Id. Problem is that i have more than one DPB.ProductTypeId in DPB table SELECT P.[Id], CASE WHEN DPB.ProductTypeId = 1 THEN SUM(DPB….