SQL Workbench - trigger before and update - sum existing date and int into new date column - mysql-workbench

i am a noob and just staring learning. I will keep my question as simple as possible. I have 2 columns. In one is a date and in second is a number which should represent months. Third column is empty and should equal the sum of first two. Eg. first column = 2022.01.01., second column=4, and result in third should be 2022.05.01. Every time i update or enter new data that should happen.
ty for your help
Eg. first column = 2022.01.01., second column=4, and result in third should be 2022.05.01. Every time i update or enter new data that should happen.

Related

Counting days between 2 dates and swapping one of the dates for another if cell if not empty - google sheets

As the title suggests I'm wondering if there is a way to count days from 1 Column from the current day, then when filling in another column it stops counting the difference in days?
I'm using the following formula (found online)
={"Days";ArrayFormula(if(A3:A="",,int(B3:I)-left(A3:A,10)))}
Column A being where my date of entry is, column B is a hidden column with every row set to the
=Today()
I have another column, Column C that I will enter the date manually after date of completion, at which point I would like it to then stop counting the days and show me the number of days between Column A and C (Date 1 and Date 2)
I'm not overly experienced in google sheets but I'm thinking maybe there's a way to
check if column C is empty, if so carry on with todays date, if it's not empty to
calculate Column C - Column A?
Would making an new column for checking if the completion date has been entered work?
ISBLANK(C:C)
If so would it be possible to get one formula to check whether True or False and determine what 2 dates to work with? Lets say Column D is for ISBLANK the following is what I think of
={"Days";ArrayFormula(if(CD:D="False",,int(C3:C)-left(A3:A,10)))}
={"Days";ArrayFormula(if(D3:D="True",,int(B3:B)-left(A3:A,10)))}
When I try this I have no luck and get a "Result was not expanded automatically, please insert more rows (1)" error message
Any help would be appreciated!
Apply the formula :
=if(B2="",today(),B2)-A2
at C2. And drag downwards. That's should do.
Please share if it work/understandable/not.
Sorry it's a bit hard to understand this question, if you could post a current and desired screenshot example that would help I think.
So, I think your best bet here is to review this video if you're wanting sheets to auto-input a time entry when a cell is modified:
https://www.youtube.com/watch?v=548dD3iXetg
And it will show you how to script a cell to enter in a time entry when another cell is edited, and then you could use a variation of formulas to calculate the difference between the days of the original minus the date from the script (such as the once referenced below or by #p.phidot )
So for an example, once you script the time entry to work in the background of the sheet, you have a formula using an IF statement to make it pull between your today date or the new date being entered.
My cell references below are an example as I can't follow the question sheet.
=if(b2="",A2-B2,A2-C2)
This way if b2 is not blank it'll do a2-c2. You could also use ISBLANK if you like.

Retrieving all entries 10 days prior to days in table, which matches where clause

I have a random table of data - with dates and numbers:
Date Open Volume abschange
2016.12.08D00:00:00.000000000 11035.76 1.74835e+008 1.30177
2016.12.09D00:00:00.000000000 11170.18 1.0383e+008 0.2994598
2016.12.12D00:00:00.000000000 11198.42 8.98117e+007 0.07331357
...
2016.12.30D00:00:00.000000000 11443.31 4.18109e+007 0.3298871
2017.01.02D00:00:00.000000000 11426.38 4.74561e+007 1.504853
So from this table, i would like to be able to create a list, which holds all the entries from 10 days prior to the days, which has abschange>1.
I thought it would be easiest to start with a focus on those dates:
Date abschange
---------------------------------------
2016.12.08D00:00:00.000000000 1.30177
2017.01.02D00:00:00.000000000 1.504853
2017.01.25D00:00:00.000000000 1.099709
2017.01.31D00:00:00.000000000 1.344625
2017.02.06D00:00:00.000000000 1.016427
2017.02.21D00:00:00.000000000 1.265196
Then create a flat list:
mynewdates: raze tablewithDateAndabschange each
which gives me:
2016.12.08D........ 2017.01.02D......
Then i get stuck, when i want to add 10 prior dates for each entry in this list.
Could i actually get my wanted result in one line of code, based on the first table or should i follow the path i am on ?
For both - if possible, what would the possible solution to this be ?
If my understanding is correct your requirement is:
for each date for which abschange>1, get last 10 dates before this date from table.
Below query will create that map. It is based on following assumptions:
Date column is unique and ordered(ascending) as it appears from your example.
If above condition is not true then it will require a minor change in below query to work with duplicates and unordered list.
Table is not keyed.
q) (tbl[`Date]a)!b#'where#'not null b:tbl[`Date] -1+(a:where 1<tbl`abschange)-\:til 10
UPDATE: Based on discussion in comment section.
Just add the second step to check if dates list for first result is empty. In that case generate last 10 dates from that date.
Finally it generates the table where each row contains prior dates(max 10) for each date with abschange>1.
q)d:b#'where#'not null b:tbl[`Date] -1+(a:where 1<tbl`abschange)-\:til 10
q)d[0]:$[0=count d 0;(t[`Date]a 0)-1+til 10;d 0]
q)([]dates:d)

Google Sheet: Pick max date out of row

Assume: in a google sheet the attendance to courses is logged with crosses.
Goal is to get the last attendance date of a person and add 6 months to it. ( course needs to be followed every six months ).
I've tried to retrieve the date of the last course in one column and add the +6months immediately and tried to have the +6 months in the second column, but I didn't succeed in both attempts.
See this link for example google sheet: https://docs.google.com/spreadsheets/d/10DG2I4VgTlOHJ5TG0qH4pJ5hJ9zsYuJCgRzEtuiTE60/edit?usp=sharing
=lookup("x",$B4:$F4,B$2:F$2)
Enter this formula in cell G4 and copy down the rows.
This formula looks for "x" (the attendance indicator) in cells in row 4 (columns B to F) - it's looking for the last instance. Then it returns the cell value from row 2 (the course date) of the relevant column.
=EDATE(G4, 6)
Enter this formula in cell H4, and copy down the rows.
This is pretty straightforward. It takes the date obtained from the lookup formula and adds 6 months.
Note that the lookup formula references column F. That's because as you create more courses you'll want the formula to automatically include them. So in cell F1, type something like "Don't use this column" - and then don't use that column!
Now when you add a new course, insert a new column to the left of the column headed "Don't use this column". This will ensure that the range in the lookup formula will expand to include the new column/course, and your latest attendance date will be updated automatically.
BTW, there's no guarantee that the date of the next course is a working day.

How to extract information meeting a specific criterion from a table?

I have a table with 6 columns and 140,000 rows, and I can't figure out how to extract specific information from the table. For instance, when I try to extract all the accidents that happens on a specific date, either it tells me that the row '12/05/2015' does not exist or it doesn't let me set 'Date' as a Row Name since the dates repeat because more than one accident happens in a day, thus giving me the error that 'Duplicate row name: '01/01/2015'.
How can I pick a date and extract all of the data that corresponds to it?
P.S. Below you can see two photos, one of the table and one of the errors I get when trying to set date as a row to make everything clearer.
if I understand correctly your matter, you want to extract from the table, the rows that contain Date1, if so try this :
new_table = table(table(:,1)==Date1,:);

Retrieving value from previous row in calculated column based on condition

I am working on data in Spotfire. The table has 4 columns:
RowID
StudID
IMT
Date
I am trying to insert a calculated column in Spotfire to get the date from the previous row for a specific StudID. The date should not be filled for first entry for a specific StudID since it does not have a previous row.
Please refer to the image for details:
This will be a calculated column using the OVER function, along with Intersect, Previous and the First aggregation.
First([Date]) OVER Intersect(Previous([Date]), [StudID])
It reads: over the intersection between (group of) the previous (to the current row) dates (which are the same) and the Student ID's (the same as the current row), give me the first row of that group. In your example, it will only ever return one date for that group, but the formula needs to be able to handle what happens if there are multiple rows. You may also need to think about whether this will happen in your data and what you're going to do about it. I.e.
StudID Date
124-639 6/12/2018
124-639 6/12/2018
124-639 6/14/2018
Building off of JasonJ's answer, it looks like his solution ran into issues when the dates of different StudIDs overlapped with one another.
So I was seeing something along the lines of this:
StudID, Date, Result
A, 10/1/2014,
A, 10/10/2014, 10/1/2014
A, 10/17/2014, 10/10/2014
B, 10/20/2014,
A, 10/21/2014,
B, 10/22/2014,
B, 10/24/2014, 10/22/2014
I created a weird workaround by adding another Calculated Column.
I doubt this is the IDEAL way to do this (I'd bet there's a better OVER function, but I couldn't identify it right off), but it looks like it's working.
First Calculated Column (Named [CalcRank]):
Rank(Concatenate([StudID],Year([Date]),If(DayOfYear([Date])<10,"0",""),If(DayOfYear([Date])<100,"0",""),DayOfYear([Date])))
Second Calculated Column:
Max([Date]) OVER (Intersect(Previous([CalcRank]),[StudID]))
Please note, you may have to pad your StudID with 0s to make sure it orders properly, like I did with the Date column.