I have a table like this:
2019.03m Bolts 100
2019.03m Nuts 50
2019.02m Bolts 10
2019.02m Nuts 100
2019.01m Bolts 50
2019.01m Nuts 10
2018.12m Bolts 10
2018.12m Nuts 10
2018.11m Bolts 20
2018.11m Nuts 30
I would like to introduce a new column called the year to date column
2019.03m Bolts 100 160
2019.03m Nuts 50 160
2019.02m Bolts 10 60
2019.02m Nuts 100 110
2019.01m Bolts 50 50
2019.01m Nuts 10 10
2018.12m Bolts 10 30
2018.12m Nuts 10 40
2018.11m Bolts 20 20
2018.11m Nuts 30 30
This sums the previous year-to-date row and resets when it reaches a new year.
I have an idea of using sums but how can I reset when I get to a new year?
I believe the below is what you are after. Note I have reversed the table in order put in time ascending order initially.
reverse update YTD:sums Number by tool,date.year from reverse t
date tool Number YTD
------------------------
2019.03 Bolts 100 160
2019.03 Nuts 50 160
2019.02 Bolts 10 60
2019.02 Nuts 100 110
2019.01 Bolts 50 50
2019.01 Nuts 10 10
2018.12 Bolts 10 30
2018.12 Nuts 10 40
2018.11 Bolts 20 20
2018.11 Nuts 30 30
If your table is ordered by date(descending in your example) you can use below query. Else you can just order it using date xdesc before running the query.
q) update ytd:reverse sums reverse num by date.year,name from t
Related
Assuming I have a specific no.of seconds as the input and I use the flutter duration package.
printDuration(aSecond * 4466000);
then the output will be
7 weeks 2 days 16 hours 33 minutes 20 seconds
what I want is for the output to include months like
1 month 3 weeks 2 days 16 hours 33 minutes 20 seconds
is there any way I can achieve this?
Get second: duration.inSeconds
Convert to milliseconds
Use DateTime.fromMillisecondsSinceEpoch(millisecondsSinceEpoch)
I have separate data like below in PostgreSQL. I want to group by data based in rounding date and time with X minute. Cost column will has aggregate function like min and max.
Date
Time
Cost
2021-05-14
10:18:00
10
2021-05-14
10:20:00
20
2021-05-14
10:21:00
30
2021-05-14
10:22:00
40
2021-05-14
10:31:00
50
2021-05-14
10:48:00
60
2021-05-14
10:59:00
70
2021-05-14
11:00:00
80
2021-05-14
11:14:00
90
2021-05-14
11:15:00
100
2021-05-14
11:17:00
110
I want it round out to nearest 3, 5,10,15,30,60,120,240 minutes.
But what specific i want to do is, when it is rounding out with round figure digits like 10,30,60,120,240 it should start with 10:15:00. ( means it should with minute 15.)
For example,
for 5 minutes, above data from 10:15:00 to 10:19:00 should be round out to 10:15:00
(Total 5 minutes considered, 10:15, 10:16, 10:17, 10:18, 10:19)
for 10 minutes, above data from 10:15:00 to 10:24:00 should be round out to 10:15:00
for 15 minutes, above data from 10:15:00 to 10:29:00 should be round out to 10:15:00
for 30 minutes, above data from 10:15:00 to 10:44:00 should be round out to 10:15:00
for 60 minutes, above data from 10:15:00 to 11:14:00 should be round out to 10:15:00
for 120 minutes, above data from 10:15:00 to 12:14:00 should be round out to 10:15:00
for 240 minutes, above data from 10:15:00 to 14:14:00 should be round out to 10:15:00
I have tried to go through many stackoverflow answer but my specific case i couldn't found.
Whichever answers i have tried of similar question either they round out to 10:10:00 for 10 minutes or for higher minutes, it starts with 10:00:00.
We have huge data set so performance is also a point to consider here.
Can anyone help for this specific case?
A test with 20 questions was applied to 300 people. We know that 8 questions had at least
100 hits and the rest at least 200 hits. Prove that some student got at least 11 questions right.
OK assume exactly 8 questions got 100 hits and the remaining 12 got exactly 200 hits. That means there were exactly 8 * 100 + 12 * 200 = 800 + 2400 = 3200 hits. If no student had at least 11 questions right, then the most any student could have got right is 10. If 300 students each got 10 answers right, that's just 3000 hits. But we know there were at least 3200 hits. Therefore, it can't be that there's no student with at least 11 hits; some student must have at least that many.
I have input data like below
CovNo type Price
10 med tot 110
10 med tot 120
10 dent tot 140
20 med tot 110
20 dent tot 130
20 med tot 120
How can i generate the output data like below
CovNo type Price
10 med tot 110
10 med tot 120
10 dent tot 140
10 Group tot 370
20 med tot 110
20 dent tot 130
20 med tot 120
20 Group tot 360
Shall i know the logic to implement the above scenario in Datastage.
Thanks in advance,
Shanmugam
Depending on the source of your data one way could be to solve it with SQL if your source is a table.
If you want or need to do it in DataStage only you could fork your data using a copy stage and have one output fed into an aggregtor stage where you calculate the sums per group. The other output is of the copy is then combined with the results of the aggregator with a funnel stage (which behaves like a union in SQL). That's it.
For the above example, we could achieve it in transformer using the SaveInputRecord() and GetSavedInputRecord() and LastRowInGroup() functions.
IBM has provided a perfect example for this type of scenario.
Note: The performance would be impacted if the data is huge as it uses cache memory. So if your data is huge, then better to split the source and perform a join after the aggregation or you could easily do it using sql if you source is a database.
I have a Group band with Detail band between the Group header and Group footer. The report is supposed to print multiple student examination records at once. I have grouped them according to the registration numbers. It works except for the fact that query results are shown twice.
as shown
Student 1
Subject score
Maths 50
English 60
kiswahili 70
Maths 50
English 60
kiswahili 70
Student 2
Subject score
Maths 90
English 60
kiswahili 60
Maths 60
English 60
kiswahili 60
insted of
Subject score
Maths 50
English 60
kiswahili 70
Student 2
Subject score
Maths 90
English 60
kiswahili 60
Add an ORDER BY to the end of your query:
ORDER BY registration_number, subject
Your data should be sent to the report template in the order in which it will be displayed. Order by student and then by subject.