I need to get cloudwatch log insights for spot terminations on only few days of the week (ex: Friday, saturday, sunday and monday). For last 3 months, I need to get the insights, entire date range can be selected through UI, but I need to filter above few days. Any help would be appreciated.
Current query without the filter for days.
filter #message like /terminate/
| stats count(*) as exceptionCount by bin(24h) as binh
| sort binh desc
Thanks in advance.
I am currently trying to count how many distinct users are active:
At least once a day
At least once a week
At least once a month
per month, for every month in the year.
Ideally the output will be like this chart that is attached
What I have done so far is following this instructions "13. User login frequency" (https://www.tableau.com/about/blog/LOD-expressions).
This example is not what I am looking for because this calculates an average in all the months of the year and I need to calculate per month how many users are active at least once a day, how many users are active at least once a week and how many users are active ar least once a month.
Thank you very much
Say you've got a table ordered by the date that captures the speed of vehicles with a device in them. And imagine you get 30 updates per day for the speed. It's not always 30 per vehicle. The data will have the vehicle, the timestamp, and the speed.
What I want to do is be able to count how many days have passed since the vehicle last went over 10 mph in order to find inactive vehicles. Is something like that possible in postgresql?
*Or is there a way to get back the row number of the table if it's sorted where the speed goes past 10, and then select the date in that row number to subtract the current date from the date listed?
SELECT DISTINCT ON (vessel) vessel, now() - date
FROM your_table
WHERE speed > 10
ORDER BY vessel, date DESC
This will tell you, for every vehicle, how long ago its speed field was last over 10.
SELECT vessel, now() - max(date)
WHERE speed > 10
FROM your_table
GROUP BY vessel;
How do I find all the user records created exactly multiple whole months/quarters ago in Postgres SQL? Is it possible?
In Postgres, you can find a date which is exactly 1 month away from a datetime field, like:
select created_at + interval '1 month' from users limit 1;
?column?
----------------------------
2016-10-05 17:05:14.811537
(1 row)
If today is 9/27/2016, I want to find all the user records created on 8/27/2016, 7/27/2016, 6/27/2016, ... 1/27/2015, etc, etc. How do I do this in SQL?
Note this isn't simply a comparison of date due to the fact that some months have 31 days while others have 28, 29, 30 days.
If today is 2/28/2015 (non-leap year), I want all the users created on the following dates: 1/28/2015, 1/29/2015, 1/30/2015, 1/31/2015, 12/28/2014, 12/29/2014, 12/30/2014, 12/31/2014, etc etc.
If today is 2/28/2016 (leap year), I want all the users created on the following dates: 1/28/2015, 12/28/2014, 11/28/2014, etc etc. (But not on 1/29/2015, 1/30/2015, 1/31/2015, as those users will be picked up the next day, see below).
If today is 2/29/2016 (leap year), I want all the users created on the following dates: 1/29/2015, 1/30/2015, 1/31/2015, 12/29/2014, 12/30/2014, 12/31/2014, etc etc.
If today is 3/31/2016, I want all the users created on 12/31/2015, 1/31/2016, but not anyone created in February 2016 because they would have been picked on previous days of March 2016.
How do I do the above with quarters instead of months?
Another question related to this is performance. If I create an index on created_at, would a whole table scan be avoided if I do this type of queries?
Thank you.
Well... If You think of it, You want to compare day number in reality, right? So You should do just that:
select
*
from
users
where
date_part('day', created_at) = date_part('day', current_timestamp)
OR
(
-- Check if this is the last day of month
extract(month from current_timestamp + '1day'::interval) <> extract(month from current_timestamp)
AND
date_part('day', created_at) > date_part('day', current_timestamp)
)
limit
1
;
And regarding Your index question - yes.
Inspiration for checking last day of a month taken from here.
Basically, if I still do not get Your requirement, You should be able to easily modify my code to meet it, if You understand it. :)
I am querying a database with records of meeting room reservations. Since we are a global company we have meeting reservations that span different months, example:
StartTime ........................ EndTime........................ MeetingName
06/30/2010 11:45PM ........ 07/01/2010 01:00AM ..... My Meeting
If I want to determine utilization for July 2010, how would I include the hour that a room was utilized in the above reservation? If my report is for only hours utilized within July.
And same holds true for if I was reporting on June...how would I only report on the 45 minutes that the meeting used in June?
If you need more information, let me know.
Since your database isn't standardized on time, then you will need to determine the timezone for each record, or, if possible, org unit, and then you can do your work with everything in the same time zone.