Select DISTINCT dates with hour segmentation - postgresql

I have a table with counters from a machine.
timestamp, input, ouput.
I need to get the input and output which happened at the start and end of a session.
A session is a different day BUT it starts at 6:00 a.m and ends at 6 a.m next day.
I use to do DISTINCT(DATE(timestamp)) to get the different days, BUT it does not cover the part wich happens next day AND covers the previous day data till 6:00 am.
How can I group by "sessions"?

Shift the time for grouping purposes:
DISTINCT(DATE(timestamp - INTERVAL '6' HOUR))

Related

Talend - How to loop over Date of Birth till the Current Year using tloop or tmap?

I have a requirement where I am giving Date of Birth from tRowGenerator. I want to loop till the current year i.e. from date of birth to current year and display values in tlogrow.
I'm able to print Years, Months, seconds, M seconds difference using TalendDate diff function but not in a loop.
I tried figuring out a solution but could not succeed. Can anyone help me out?
Total result in 1 log:

Add default parameter regarding time SSRS

I am developing a report on task performance based on their working shift. Day shift will start on 9am to 9pm and night shift will start from 9pm to 9am. I would like to display data based on their current working shift as example, if someone is working on day shift and view report on 8pm, the report will show from range 9am to 8pm only and if user working for night shift, the report will only show from 9pm to 9am range
I have a dataset and parameter which is #begin_date and #end_date (eg. Monday, Tuesday...), #begin_hour and #end_hour. I got column "time" where the task complete.
Can someone help me?
EDIT:
Sorry, can you guide me, this is my propose sample code. Let say the current date is monday
If time <= 21 begin show 9am to (current time, limit 9pm monday) end Else if time >= 21 Begin Show 9pm to (current time, limit 9am tuesday)
End
How can i do this in sql?
Don't use a parameter at all. Add the logic into the stored proc or query that returns the results. Only show results from the beginning of the shift up to the current time.

how to find number of days since 28th of last month till 27th of current month in db2

I need to generate a report on 28th of every month .
So for that I need to run an autosys job.
In that I have a query with the condition
validation_date >= (number of days since last run)
Could you please help me on this .How can I achieve this condition in DB2 ?
This is a monthly job.So I don't want to hard code my previous run date in the query .At the same time I need to get a condition which satisfies for all the months .
Note :
If the query is running on feb 28th ,then feb 28th is not included. I need to get data from january 28th(included) till feb 27th(included)
similarly for march 28th run ,I need to get data from feb 28th(included) till march 27th(included)...Thanks in advance.Please help
Consider putting your report generation in a procedure, and parameterizing the start and end dates. In other words, have something like this:
create procedure monthly_report(
start_date date,
end_date date
)
language sql
begin
... report queries here ...
end
Now you potentially have something much more flexible (depending on the report requirements). If, in the future, you want to run a report on a different day, or for a different length of time, you will be able to do that.
Once you design it this way, it also may be easier to set the dates in your job scheduling script, rather than in SQL. If you did it in SQL, you could do something like this:
call monthly_report(
(select
year(current timestamp - 2 months) ||'-'||
month(current timestamp - 2 months) ||'-'||
'28' from sysibm.sysdummy1
),
(select
year(current timestamp - 1 month) ||'-'||
month(current timestamp - 1 month) ||'-'||
'27' from sysibm.sysdummy1
)
)
You may need to tweak it to handle some edge cases (I'm not exactly sure if you care what happens if it runs on the 29th of the month, and if so, how to handle it). But you get the basic approach.
You can use DAY() function that extracts day of month from date and you can use it for triggering job. for example where day(param)=28.
other two parameters can be calculated with date calculation , here is example for trigger , date_to value and date_from value
select day(timestamp_format(20170228,'yyyyMMdd') ),timestamp_format(20170228,'yyyyMMdd')- 1 DAY,timestamp_format(20170228,'yyyyMMdd') -1 month from sysibm.sysdummy1;
if your parameter/column is date/timestamp you can remove timestamp_format(20170228,'yyyyMMdd') function and just put your column/parameter

Confused with dates and days in cron jobs

I am having trouble understanding how dates and days work together in a cron job.
Say I have the following command:
0 23 5 1 3 COMMAND
This translates to 23:00, on 5th of January, on Wednesday.
The problem is, that January 5th is a Sunday. How exactly will this command work out? Is the command going to be executed for both January 5th AND for every Wednesday on the month January? Or will it execute just the '5 1' bit?
I am really sorry if it is a really basic question and possibly stupid but to me it really does not make any sense.
Thank you in advance!
Commands are executed by cron when the minute, hour, and month of year fields match the current time, and at least one of the two day fields (day of month, or day of week) match
Ref: Man Page

Creating Dynamic Date Column Headings in Cross Tab for Business Objects

BO Version: 12.1.0 on Infoview,
O/S: W7
I am creating a report in infoview, which is a cross-tab. I have departments on the row side and for the column I want to have all Saturday dates dynamically displayed, and this is dependent on the date prompt values I put in to the report when I run it.
So if I put in for the prompts Dec the 08th 2013 to Jan the 04th 2014 I should see 4 Saturday dates (14th/21st/28th/04th) along the column headers.
I started off using a variable and using the function relativedate, which gave me all the dates I wanted:
=RelativeDate(LastDayOfWeek([Query 1].[Episode End Date]);-1)
but because I used -1 to get the Saturday date it was giving me the Saturday before the earliest prompt date, so I was getting these dates instead:
(07th/14th/21st/28th/04th)
Is there a way I can get these dates but ignore the previous day (the 7th) before the start prompt date?
I want to have this dynamic so that if I put a date range in it shows me all the saturday dates within that range along the top of the report regardless of the date range period.
Andrew
The reason you're having trouble is that WebI (being ISO compliant) considers a week to run from Monday to Sunday, but your reporting week ends on Saturday.
So, I would approach it this way:
=RelativeDate(
LastDayOfWeek(
RelativeDate([Query 1].[Episode End Date];1)
)
;-1)
If we evaluate some dates with this logic, we'll see the desired result:
Testing 12/8 (Sunday):
Add one day = 12/9
Get Last Day Of Week = 12/15
Subtract one day = 12/14
Testing 12/12 (Thursday)
Add one day = 12/13
Get Last Day Of Week = 12/15
Subtract one day = 12/14
Testing 12/14 (Saturday)
Add one day = 12/15
Get Last Day Of Week = 12/15
Subtract one day = 12/14
I'm at home and don't have access to WebI right now, so I can't test this myself, but the logic should be sound.