Category "sql"

PostgreSQL: Getting the sum of the difference in dates from two separate tables

The following code: SELECT ets.event_id, ets.event_date, dtn.don_date, dtn.don_date - ets.event_date AS date_diff FROM events ets, donation dtn GROUP BY ets.eve

Complex row manipulation based on column value in SQL or Power Query

I have a call dataset. Looks like this If a call about a certain member comes in within 30 days of an "original call", that call is considered a callback. I ne

add generated column with aggregated over a partion and sort

I am trying to add a calculated column that computes a rolling average of a sorted partition. I can make it work as a query but cannot seem to get the result to

Creating Custom Join in Django

I am struggling to create the correct prefetch behavior in Django. Here is the outline of the problem: Each Account has DailyQuotes, updated daily at different

MySQL correlated subquery very slow when range is included

DB Fiddle: https://www.db-fiddle.com/f/u1N4YYV3wmiWndnZNb95xz/5 For the following tables nodes and leaves, with nodes having just 9 records and leaves having a

PostgreSQL duplicate key value violates unique constraint while using on conflict do nothing on insert

Table def: CREATE SEQUENCE IF NOT EXISTS lazy_product_stock_id_seq; CREATE TABLE "public"."lazy_product_stock" ( "id" int4 NOT NULL DEFAULT nextval('lazy_pr

How can I solve this issue on Mac M1 Caused by: java.lang.Exception: No native library is found for os.name=Mac and os.arch=aarch64

I solved this issue with the code below in my build.gradle allprojects { configurations.all { resolutionStrategy { force 'org.xerial:sqlite-jdbc:3

Generating counts of open tickets over time, given opened and closed dates

I have a set of data for some tickets, with datetime of when they were opened and closed (or NULL if they are still open). +------------------+-----------------

How to join these tables with columns that don't always match?

I have 2 tables: google_analytics and marketing_costs. How can I join these 2 columns (google_analytics['source'] with marketing['medium']) even tho they don't

ClickHouse: How to store JSON data the right way?

I'm going to migrate data from PostgreSQL database to Yandex's ClickHouse. One of the fields in a source table is of type JSON - called additional_data. So, Pos

Presto Weighted Moving Average Syntax Error

I'm trying to run the weighted moving average Silota query with similar data in a Presto database but am encountering an error. The same query in the Redshift d

Conversion failed when converting the nvarchar value to data type int sql server

I have a table. There is data in this table and there is a checkbox next to each data. Multiple selection is possible. After the user makes a selection, the id

Redshift SQL Query Between Current Date and 7 days ago

I've been trying to filter the data for the last X number of days. All these columns work as standalone results when I remove the time filter from the where cla

Select Statement inside of

I get error "Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used

SQL COUNT with values from 2 tables

I have following two tables: comments comment_post_ID status comment_type 1 complete course_status 2 complete course_status a1 complete lesson_status a2 passed

simplify sql query Oracle database

Task: Write a query that returns a list of houses from the TB_ELEKTROSTAL_2018 table. It is considered that all subscribers who have the same address belong to

Querying pivot table to return a list of referred rows

I have these 6 tables and query which returns everything I want, but I want to add a new pivot table, so I can get a list of rows linked to it. Query: SELECT DI

Postgres array_position(array, element) sometimes 0-indexed?

Postgres method array_position(array, element), like other things in SQL, is 1-based. For example: SELECT array_position(array[4,5,6], 5) -- returns 2 But,

Extracting date and time from oracle

I have a table in which there is a field last_update_date in which the date is displayed in short form like 25/02/2015.If I want to extract the date in long dat

PostgreSQL- Function to update 3 shared columns from table B on table A

The main goal is to create a function that updates 3 columns on another table (the update of the 2 columns from the first table trigger the update on the second