I have a table in Postgres database "logs" which holds the error logs with their creation date
sample query : Select creation_date from logs
returns
"2011-09-20 11:27:34.836"
"2011-09-20 11:27:49.799"
"2011-09-20 11:28:04.799"
"2011-09-20 11:28:19.802"
I can find out the latest error using the command
SELECT max(creation_date) from log;
which will return "2012-02-06 12:19:28.448"
Now what I am looking for a query which could return the errors occured in last 15 minutes.
Any help on this will be appreciated
This should do the trick:
SELECT * FROM logs WHERE creation_date >= NOW() - INTERVAL '15 minutes'
Related
I'm using state_window syntax in TDengine database.
My SQL statement is:
select t.*
from (
select ts,
tbname as app_id,
tenant_name,
queue_code,
task_name,
sum(allocated) as allocated
from yarn
where ts > now - 6m
partition by ts,tbname,tenant_name,queue_code,task_name
) t
partition by ts, app_id, tenant_name, queue_code, task_name
state_window((CASE WHEN allocated > 100 THEN 1 ELSE 0 END));
Then I encountered an error report:
DB error: Window query not supported, since the result of subquery not
include valid timestamp column
I don't particularly understand its meaning, and how to fix the problem.
I am working through Snowflake workshop lab tutorial. I am up to 7.2.4/7.2.5.
The query in 7.2.4 executes fine:
set query_id = (
select query_id
from table(information_schema.query_history_by_session (result_limit=>5))
where query_text like 'update%' order by start_time limit 1
);
However the query in 7.2.5 gives an error:
create or replace table trips as (
select * from trips before (statement => $query_id)
);
The error given is:
SQL execution internal error: Processing aborted due to error 300002:1177671206; incident 8702198.
Any thoughts on what is going wrong here?
i want to send the Email on Certification expiry when 21,14,7,3,2,1 days are left by a scheduler which picks the data by the Query .
i am using the ExpiryNotification bit col.as a flag(as previous it used to sent on 30 days only)
the data in the Query is picked from scheduler.now if i have to do changes in the Query to implement this logic i will need to change the col from bit to int and check the Notification col.but what if the Scheduler does not run when 21 days are left for some odd reason then what will happen.is there any other way to implement this Logic by sql server ?
it will make the ExpiryNotification col value to 1 when the mail is send
exisitng Query (checking only 30 days)
Select * from wsm_certification
where
(DATEDIFF(d, GETDATE(), wsm_Certification.RenewalDate) = 30
and wsm_Certification.ExpiryNotification = 0)
You may try something like this
(DATEDIFF(d, GETDATE(), wsm_Certification.RenewalDate) = 21 OR (DATEDIFF(d, GETDATE(), wsm_Certification.RenewalDate) = 14
Use in operator to check multi values
Eg:
Select * from wsm_certification
where
(DATEDIFF(d, GETDATE(), wsm_Certification.RenewalDate) in (21,14,7,3,2,1)
and wsm_Certification.ExpiryNotification = 0)
I'm trying to find a better way of finding duplicates in SQL Server. This took over 20 minutes to run with just over 300 million records before results started showing in the results window within SSMS. Another 22 minutes elapsed before it crashed.
Then SSMS threw this error after displaying 16,777,216 records:
An error occurred while executing batch. Error message is: Exception of type 'System.OutOfMemoryException' was thrown.
Schema:
ENCOUNTER_NUM - numeric(22,0)
CONCEPT_CD - varchar(50)
PROVIDER_ID - varchar(50)
START_DATE - datetime
MODIFIER_CD - varchar(100)
INSTANCE_NUM - numeric(18,0)
SELECT
ROW_NUMBER() OVER (ORDER BY f1.[ENCOUNTER_NUM],f1.[CONCEPT_CD],f1.[PROVIDER_ID],f1.[START_DATE],f1.[MODIFIER_CD],f1.[INSTANCE_NUM]),
f1.[ENCOUNTER_NUM],
f1.[CONCEPT_CD],
f1.[PROVIDER_ID],
f1.[START_DATE],
f1.[MODIFIER_CD],
f1.[INSTANCE_NUM]
FROM
[dbo].[I2B2_OBSERVATION_FACT] f1
INNER JOIN [dbo].[I2B2_OBSERVATION_FACT] f2 ON
f1.[ENCOUNTER_NUM] = f2.[ENCOUNTER_NUM]
AND f1.[CONCEPT_CD] = f2.[CONCEPT_CD]
AND f1.[PROVIDER_ID] = f2.[PROVIDER_ID]
AND f1.[START_DATE] = f2.[START_DATE]
AND f1.[MODIFIER_CD] = f2.[MODIFIER_CD]
AND f1.[INSTANCE_NUM] = f2.[INSTANCE_NUM]
Not sure how much faster this is, but worth a try.
SELECT
COUNT(*) AS Dupes,
f1.[ENCOUNTER_NUM],
f1.[CONCEPT_CD],
f1.[PROVIDER_ID],
f1.[START_DATE],
f1.[MODIFIER_CD],
f1.[INSTANCE_NUM]
FROM
[dbo].[I2B2_OBSERVATION_FACT] f1
GROUP BY
f1.[ENCOUNTER_NUM],
f1.[CONCEPT_CD],
f1.[PROVIDER_ID],
f1.[START_DATE],
f1.[MODIFIER_CD],
f1.[INSTANCE_NUM]
HAVING
COUNT(*) > 1
I am trying to fetch records after a certain date.
I used the below in code:
qstr = "SELECT * FROM Comment where date > '"+str(max_date)+"' order by date desc limit 10"
comments = db.GqlQuery(qstr)
I have the console log I have qStr as follows:
SELECT * FROM Comment where date > '2013-03-07 04:33:31' order by date desc limit 10"
But this does not yield any records (There are records in the DB).
I also tried passing as date time:
comments = db.GqlQuery("SELECT * FROM Comment where date > :1 order by date desc limit 10",
miscUtils._datetime_from_str(max_date))
This also does not yield any results. Can you please let me know as what I'm doing wrong?
(I'm using the following code to convert date string to date http://code.activestate.com/recipes/577135-parse-a-datetime-string-to-a-datetime-instance/)
Also, I tried debugging the statement in App Engine console, and I was not able to do so.
Thanks in advance
I got it to work as follows:comments = db.GqlQuery("select * from Comment where date > :1 order by date desc limit "+MAX_COMMENTS_PER_FETCH_STR, datetime.datetime.strptime(max_date, "%Y-%m-%d %H:%M:%S").date())
Thanks everyone for your help