I’m working with table, its structure looks like this: from_date DATE %Y-%m-%d to_date DATE %Y-%m-%d person VARCHAR tax INT Table shows that in period between date_from and date_to for such person there was such tax The whole point is that these periods can intersect and activities can sum. Roughly spea…
SQL GROUP BY IN CASE STATEMENT
i have one table i would like to classify the apple as below i try to add code as below, but its not like what I expected I try this code also, but got error Answer You want conditional aggregation here, which involves summing over the CASE expression:
Failed to add the foreign key constraint. Missing index for constraint ‘information_ibfk_1’ in the referenced table ‘informacia’
What is the problem with these tables? I want to create foreign key for second one Answer In order for a table to add a foreign key constraint, the referenced column (zip_code in this case) must be a PRIMARY KEY or must have a UNIQUE constraint (ideally with NOT NULL). I modified the SQL statements according …
Junction table in PostgreSQL
I have two tables I created a junction table called “recipes_ingredients” My first question is: is it correct how I created the “recipes_ingredients” table? Do I need the “id” or I can just have the two foreign keys “fk_recipe” and “fk_ingredient”? A…
SQL: Grouping Paired Rows Without Field to Aggregate On
So say I have the following: Timestamp Event_Name 10:47:00 RESUME 10:37:52 SUSPEND 10:26:20 RESUME 09:48:27 SUSPEND 09:39:13 RESUME 09:15:38 SUSPEND 09:11:42 RESUME I want to be able to pair them as such: Suspend Resume null 10:47:00 10:37:52 10:26:20 09:48:27 09:39:13 09:15:38 09:11:42 If each pair had anoth…
Creating a cumulative sum column with_order in R
I’m working alongside a SQL tutorial using queryparser and tidyquery in R. This has been going well until I was asked to do: Tidyquery reported that it did not support OVER functions so I am trying to replicate the OVER (PARTITION BY…) function with dplyr. This led me to with_order(order_by =̷…
SQL: Getting Missing Date Values and Copy Data to Those New Dates
So this seems somewhat weird, but this use case came up, and I have been somewhat struggling trying to figure out how to come about a solution. Let’s say I have this data set: date value1 value2 2020-01-01 50 2 2020-01-04 23 5 2020-01-07 14 8 My goal is to try and fill in the gap between the two dates
Find all Asian cities whose population is greater than population of every single Nordic country (attribute region)
I’m doing a task where I’m supposed to find all Asian cities whose population is greater than the population of every single Nordic country (attribute region). (The diagram is shown on the uploaded …
How to select all rows that are related to satisfied condition in ms ACCESS
I have the following data in table VehiclesAccSummary: I am not sure how to do this but what I want is a query that would return all rows where there where only two car in the accident and it was a …
Why does this conversion to date fail on some rows in my table and not other rows when I use an IIF
I have this table and data: CREATE TABLE dbo.tBadDate ( BadDateID int NOT NULL, StartDate nchar(20) NULL, CONSTRAINT [PK_tBadDate] PRIMARY KEY CLUSTERED ( [BadDateID] ASC ) ); …