I am using Esper with Twitter4J to process Data from the Twitterstream. Now I want to compare current Data with all Data from the last 10 seconds. I want to check, if someone posts two or more Tweets in a time slice of 10 seconds. Whats Statement for such a check? Or do you check such outside of the Esper Statement?
My statement is right now:
String expression = "select user, sum(ctr) from Tweet.win:time(10 seconds) having user IN (select user from Tweet.win:time(10 seconds))";
I know that this is wrong, because two identical variables are being compared, but i don't know how to check, if the same user was ound in the last 10 seconds...
I appreciate any help.
I've figured it out, it must be:
select user, count(user), text from Tweet.win:time(1sec) group by user having (count(user) > 1)
Related
I am trying to run a simple query against any of the tables contained in SNOWFLAKE.ACCOUNT_USAGE schema but for some reason it is taking up a long time to run even if I try to limit it to show only the first row, like the following example:
SELECT * FROM "SNOWFLAKE"."ACCOUNT_USAGE"."ACCESS_HISTORY" limit 1;
Is that a normal behavior? If not, can someone help me to figure out why this is happening?
Its always a good practice to add a WHERE condition so the optimizer can make use of query pruning.
If you know your objects were accessed within the past say 24 hours, can you add a date filter and see if that helps?
SELECT * FROM "SNOWFLAKE"."ACCOUNT_USAGE"."ACCESS_HISTORY"
WHERE QUERY_START_TIME > CURRENT_DATE() - 1
limit 1;
More info on mirco-partitions and query pruning: https://docs.snowflake.com/en/user-guide/tables-clustering-micropartitions.html#query-pruning
Many years ago I knew SQL quite well but apparently it's been so long I lost my skills and knolwedge.
I have a number of tables that each track a given event with additional metadata. One piece of Metadata is a timestamp in UTC format(2021-08-11 17:27:27.916007 UTC).
Now I need to count how many times the event occurred per minute.
Col 1, Col2
EventName, Timestamp in UTC
I am trying to recall my past knowledge and also how to apply that to BQ. Any help is appreciated.
If I'm understanding well, you could transform your Timestamp into minutes and then group by it.
SELECT count(*) AS number_events,
FLOOR(UNIX_SECONDS(your_timestamp)/60) AS minute
FROM your_table
GROUP BY FLOOR(UNIX_SECONDS(your_timestamp)/60)
So it transforms your timestamps to unix_seconds, then divide by 60 to get minutes and floor() to skip decimals after the division.
If you have multiple type of events in the same table, just add the name of the event to the select and to the group by
The first step would be to group by event column.
Then the Timestamp events can be counted.
Select Col2_EventName, count(Timestamp )
group by 1
Depending on your data, some more transformation have to be done. E.g. ignore the seconds in the timestamp and hold only the full minutes, as done in the answer from Javier Montón.
I'm new here so please be gentle, my first question after using this website for a long time regards the below:
I'm trying to create a sum of count of events in the past 30 days:
select key, sum((COALESCE(count(*),0)))
from table
Where date>= '2016-08-13'
And date<= '2016-09-11'
group by key;
but the sum doesn't seem to work. i'm looking at the last 30 days, and i would like to count any row that exists for each key, and then sum the counts (i need to count on a daily basis and then sum all day's count).
If you can offer any other way to deal with this issue i'm open for suggestions!
Many thanks,
Shira
You can't nest aggregate functions in HQL (or SQL). However, if you just want a count of records falling within range for each key, then you can simply just use COUNT(*):
select key, count(*)
from table
where date >= '2016-08-13' and
date <= '2016-09-11'
group by key;
It looks like there was a couple things wrong with your code.
I've written this for you, haven't tested it but it passes the syntax test.
SELECT COUNT(key) AS Counting FROM tblname
WHERE date>= '2016-08-13'
AND date<= '2016-09-11'
GROUP BY key;
And this might help you. You should definitely be using COUNT for this query.
I'm not sure if it's related but there might be an issue with calling a field 'key' I kept receiving syntax errors for it.
Hope I was able to help!
-Krypton
My data is stored in Oracle and the only way I can run a report with it is using Crystal Reports. I have a set of data that looks like this ,,,,,,,,,,1, or ,1,,,,,,, or ,1,,,,,1,,,,1,. There are more variations.
Each one means a value is true for a record. There are about 54 'ticks/commas' What I want is all records with the one at the X spot. So for one report I may want all records in the 10th spot that have a 1. There may be other times where I want the records where the 1 is after spot 36. I agree it will pull other records but the main once I want is the X spot.
How do I get this? I tried a Like command but that does not narrow the data down far enough. I am familiar with SQL but not Crystal.
Any help would be great. TIA
In Crystal, you might try setting up a Parameter Field to hold a numeric value (1 to 54) then use that in a formula as the Record Selection. You'll be prompted to enter the parameter when you run the report.
In record selection i was initially going suggest the following which would bring back all records with 1 in the 12 spot. But this makes it hard to bring back a range.
split({yourfield},",")[12] = 1
This will bring back the same
instr({#test},"1") = 12
Then for your suggestion above you could use the following to bring back any record if it has a one in any spot after 36
instr({#test},"1") >= 37
As long as there is only one 1 in the field you can use this for other ranges as well.
Actually I don't want to disturb both answerts by Clayton Morris and CoSpringsGuy hence posting my answer.
You need to combine both the solutions to get the desired result.
Create a number parameter and provide either 1 to 57 numbers or keep just a filed to enter desired number.
Now in record selection use the formula given by CoSpringsGuy
if instr({databasefield.column},"1") = {?Inputnumber} --parameter field
then {databasefield.column}
I haven't been able to find an answer to this all over the interwebs. This is the issue I have:
I have an SQL View that has a Time type field, which includes the Time an employee stayed logged into a system.
When I create a Pivot Table in Excel to get the Total Time agent has spent logged in, Excel won't sum the Time field, it can count it, but not sum or average. Gives me 0 in both Sum and Average, but in Count it shows 24 (24 hour intervals).
I have tried multiple convert/casts to translate the Time data to a format that Excel understands (it seems to think it's a varchar/string type) but to no avail.
Any suggestions?
Import csv file into MS Access and select appropriate type during import (long int should work I assume), save database. Open excel and import the access database. Access is usually my go to option when excel provides me with annoying format issues.
Have you tried to pivot the data in SQL via a query?
So this is what I ended up doing for the sake of someone who might run in the same problem as I have:
First on my SQL query I transformed the Time data to an integer (in seconds) by using the following:
(DATEPART(hh, Login_Time) * 60 * 60) + (DATEPART(MINUTE, Login_Time) * 60) + DATEPART(s, Login_Time) as Login_Time_Secs
Then in my Pivot Table in Excel I created a Calculated Field that did the opposite calculation, by transforming the seconds into Excel Time:
Login_Time = Login_Time_Secs/(60*60*24)
Formatted the Login_Time field to an Hour format [h]:mm
Done! Now my Pivot Table in Excel can Sum/Average the time logged in per employee.
This didn't require for me to change my SQL data source (which would be a big hassle), it only changed the View Query to where the Pivot Table connects to.
I hope this helps someone.