teradata remove periods from one table that are in another table - teradata

tables for the problem
I am trying to remove any periods or part of periods for the same id from one table if the period, or part of the period, appears in another table in Teradata.
In the image as a reference.
I would like to remove any periods from the start table if they appear in the remove table to get the result table
All the group A rows would be removed and the B rows would be kept with the second B row being split into two periods.
Is this possible?

Related

Ordering SQLite table by sum of two columns

I have a database that has two integer columns, and I'm trying to find a way to select the top 'x' amount of rows with the highest sums of these two columns. I'm trying to eliminate the need of creating a third column that stores the sum of the two, unless there's a way to to automatically update this column every time one of the other two are altered. I'm using SQLite by the way, as I know there are some slight differences here and there between SQL/SQLite syntax.
Any help is appreciated.
Something like
SELECT a, b
FROM yourtable
ORDER BY a + b DESC
LIMIT :x
should do it.

Conditionally selecting duplicates and selectively choosing which duplicate to keep

I am currently working with a large data frame for a study involving 486 observations with 7 variables in R studio (see attached image for a sample of dummy data). Two of the variables are ID numbers: the first ID number is unique for each individual person. However, sometimes a person appears more than once on the list, so there are duplicates of this first ID number. The second ID number is also unique for each person, but it lists a study visit number as a suffix (to signify that they came in over a period of time). Thus, this second ID number does not have duplicates. For example, say there was someone with a first ID number of 0001, and they have two second ID numbers of xx0001_1 (for their first visit to the lab) and xx0001_2 (for their second visit to the lab). However, the vast majority of people in the data frame only came in for one visit, so they do not have a duplicate first ID number (or second ID number, in that case).
My problem is this: I want to select only those that have duplicate first ID numbers and then filter out each of their data points such that I only keep their second visit. For example, I need to only select those with duplicate first ID numbers such as "0001", and among those I want to filter out the "xx0001_1" visit and only keep the "xx0001_2" visit.
I know that I can use the "distinct" function for the first ID number, but the problem is that this eliminates the second of the second ID numbers (e.g. xx0001_2) and keeps the first one (e.g. xx0001_1). I want to do the opposite: I want to eliminate duplicates of the first ID number, but only keep the rows that have the second visit in their second ID number (e.g. keep xx0001_2 but remove xx0001_1). I'm very new to R/coding. How can I do this? Thank you!
Example data sample
distinct(.data, ID 1, .keep_all = T)
However, this code only preserves the first row. I want to eliminate the first row and instead only preserve the second row. Thanks!

How to select first row of each table?

I have a SQL database with 30 tables ordered by company names. They are 30 stocks. Each table has columns date, high, low, close and volume.
My question is: how do I select the first record of each table in SQL?
Is it
FROM TOP 1 * SELECT aaple_30min?
I tried
SELECT *
FROM bac_30min
LIMIT 1
but this gives me only for one table.
I have decided to write the query in R, where I will loop through the companies in question and use the paste function to make calls by replacing above "bac_30" with company names as strings.

Subtract Row Count in View A from Row Count in View B (Drupal)

I've two Views using Table Summarize to count their rows. One view is student arrivals and the other is studen departures.
I want to subtract the row count in ViewB (departures) from ViewA (arrivals) and combine them into a net figure. Perhaps combine in another view.
I am aware of union as a tool for merging but I don't want to combine the result set, I only want to subtract the row counts.
Any suggestions much appreciated!

ssrs total values for one column (tablix)

I have the following tablix
which needs to produce something like this:
I can populate the Burger flipper and cashier and all their values easily with row grouping. What I cannot figure out is how to sum the Charged column. Thoughts?
Edit:
I've tried adding the following to sum my charges but get an error saying I cannot nest aggregates:
=SUM(Round((Round(Sum((((Fields!Amt_Time_Min.Value) + (Fields!Amt_Time_Hrs.Value * 60))/60)),3) * Round(Fields!ServHrRate.Value)),2))
Assuming that Total row is the footer of row group insert into it's Charged cell function:
=SUM(Fields!Charged.value)
(substitute with a real dataset field). It should summarize all the values of the details row.

Resources