I'm trying to count the occurrences of the same value using InfluxQL.
I have the following, when I run SELECT distinct("name") from "table"
1970-01-01 01:00:00 | value 1
1970-01-01 01:00:00 | value 2
1970-01-01 01:00:00 | value 3
1970-01-01 01:00:00 | value 4
I am able to see the occurrences of each value when I run SELECT count("name") FROM "table" WHERE "name" = 'value 1'
1970-01-01 01:00:00 | 239
What I would like to end up with is the above but for each name.
1970-01-01 01:00:00 | value 1 | 239
1970-01-01 01:00:00 | value 2 | 137
etc.
If I run SELECT "name" FROM "table" GROUP BY "name" then I have all of the values in one large result, so it's just how I count them from there.
I would also like this to change with the time interval.
Related
I have two columns where I cam looking up a value in another sheet for date and value. The values are in rows and I want to display the results in columns.
How the source data looks
How I'm pulling it
I can't figure how to make the formula drag down where Column value changes, but the Row value stays the same. Meaning, AA1 would drag down to AB1, AC1, etc.
105 Weds Feb 1 at 9:00 AM
101 Weds Feb 1 at 12:00 PM
115 Weds Feb 1 at 4:05 PM
111 Weds Feb 1 at 9:40 PM
116 Thurs Feb 2 at 12:05 AM
97 Thurs Feb 2 at 1:20 PM
='Data'!B1 ='Data'!B3
='Data'!C1 ='Data'!C3
='Data'!D1 ='Data'!D3
I've tried using an array and it works for the displaying the next value in the Column, but not the next value in the Row like I want.
I've also tried some scripts I was able to lookup but wasn't successful.
I have two columns in Google Sheets:
B | C
Date | Time
2/21/2022 | 7:30:02 AM
2/21/2022 | 7:48:02 AM
2/21/2022 | 8:24:05 AM
2/21/2022 | 2:34:02 PM
2/21/2022 | 2:56:02 PM
2/22/2022 | 8:05:00 AM
2/22/2022 | 8:15:00 AM
2/22/2022 | 3:00:02 PM
2/22/2022 | 3:15:02 PM
2/22/2022 | 3:25:14 PM
etc...
DateTimeData Image
There are dozens of entries for Time in a single day. I would like to find the earliest Time and latest Time for each day within a Time range between (7:30:00 AM to 8:30:00 AM) AND (2:30:00 PM to 3:30:00 PM).
The result will be two Time values for each day.
i.e.
B | C
Date | Time
2/21/2022 | 7:48:02 AM
2/21/2022 | 2:56:02 PM
2/22/2022 | 8:05:00 AM
2/22/2022 | 3:15:02 PM
etc..
GoalResult Image
I was able to find the values of each day within the Time Range using this formula, but have not been able to extract the Lowest and Highest Time values for each day.
=ArrayFormula((IF(C2:C="","",IF((C2:C1000>VALUE(timevalue("7:30 AM")))(C2:C1000<VALUE(timevalue("8:30 AM"))),C2:C1000,IF(C2:C="","",IF((C2:C1000>VALUE(timevalue("2:30 PM")))(C2:C1000<VALUE(timevalue("3:30 PM"))),C2:C1000,0))))))
Any ideas? Thanks!
Try
=query(A:B,"select A,min(B),max(B) group by A label max(B) 'End time' , min(B) 'Start time' ")
I'm using Rails 5 and PostgreSQL 9.5. I have a table with the following columns .
cindex=# \d crypto_index_values;
Table "public.crypto_index_values"
Column | Type | Modifiers
------------+-----------------------------+------------------------------------------------------------------
id | integer | not null default nextval('crypto_index_values_id_seq'::regclass)
value | double precision |
index_date | timestamp without time zone | not null
created_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
Given a point in time (say "2017-07-29 11:10") stored in a variable "my_date", how would I write a Rails finder query that returns a single Rails entry that returns the row with the smallest "index_date" that was also at least 24 hours away from "my_date"? So if I had this table data
14 | 133.951211424387 | 2017-07-31 19:10:03.235566 | 2017-07-29 19:10:03.267727 | 2017-07-31 19:10:03.267727
15 | 133.951211424387 | 2017-07-31 19:20:03.59569 | 2017-07-28 19:20:03.629418 | 2017-07-31 19:20:03.629418
16 | 139.104155235946 | 2017-07-31 19:30:08.037045 | 2017-07-31 19:30:08.04715 | 2017-07-31 19:30:08.04715
and given my example, I would expect the query to return the row with id "15" because the row with id "14" is not 24 hours away from my example. Normally this kind of query would work
CryptoIndexValue.where('index_date = ?', my_date - 1)
but since there isn't an entry exactly 24 hours away, it doesn't.
I don't think your example values quite work -- at least I don't see how you would choose that value from the table with that index date, subtracting a day. Do you mean "the row with the earliest date which is also at least 1 day in the future from my_date"?
CryptoIndexValue.
where('index_date > ?', my_date + 1.days).
order(:my_date, :id).
take
I added :id to the order by in case you need a tie-break on two rows that have the same index_date, but remove it if that's impossible due to a constraint.
Maybe you mean to subtract one day instead of adding, though.
You should use > operator combined with order.
CryptoIndexValue.order(:index_date).find_by('index_date > ?', DateTime.now - 24.hours)
I would like to find out which driver is available during a certain time based on his start and end datetime.
I have two worksheets.
Worksheet1 displayes the start and end time of drivers in datetime:
Driver | Start Time | End Time
------------------------------------------
Driver 1 | 25-05-2015 09:00 | 25-05-2015 15:00
Driver 2 | 25-05-2015 15:00 | 25-05-2015 21:00
Driver 2 | 26-05-2015 09:00 | 26-05-2015 15:00
Driver 1 | 26-05-2015 12:00 | 26-05-2015 17:00
Worksheet2 displays the start date of a tour
Tour 1 | 25-05-2015 11:00
Tour 2 | 25-05-2015 16:00
Tour 3 | 25-05-2015 17:00
Tour 4 | 26-05-2015 09:00
I would like to query in worksheet 2 which driver from worksheet 1 is available during the time of the tour start.
=QUERY(Worksheet1!A:C,"select A where C <= date '"&text(A2,"yyyy-MM-dd")&"'",0)
But I understand that I will need to be working with timedate instead (to get the actual times of the start and end of the shifts) and I will need to query an interval.
If you want to use dates and times, you need datetime instead of date. And since there is an interval, another comparison should be made with column B. The query string, shown with linebreaks for readability, would be
"select A
where B <= datetime '" & text(A2, "yyyy-MM-dd hh:mm:ss") & "'
and C >= datetime '" & text(A2, "yyyy-MM-dd hh:mm:ss") & "'"
This ensures that the datetime in A2 is between the datetimes in columns B and C.
I have NSDate stored in my sqlite table in double format - using timeIntervalSince1970 funciton.
Now I want to retrive unique date combinatios like
{
January 2014
December 2013
November 2013
December 2012
November 2012
October 2011
}
Data have to be in sorted order. How can I get data in this format?
I have tried with Date function
SELECT date(DateInterval, '%m', '%Y') FROM MyTable
but got no result.
Hope for good helps :)
Thanks in Advance.
Are you looking for something like this?
SELECT CASE m
WHEN '01' THEN 'January'
WHEN '02' THEN 'Febuary'
WHEN '03' THEN 'March'
WHEN '04' THEN 'April'
WHEN '05' THEN 'May'
WHEN '06' THEN 'June'
WHEN '07' THEN 'July'
WHEN '08' THEN 'August'
WHEN '09' THEN 'September'
WHEN '10' THEN 'October'
WHEN '11' THEN 'November'
WHEN '12' THEN 'December'
END || ' ' || y AS dates
FROM
(
SELECT DISTINCT
strftime('%m', DateInterval, 'unixepoch') m,
strftime('%Y', DateInterval, 'unixepoch') y
FROM MyTable
) q
ORDER BY y DESC, m DESC
Sample output:
| dates |
|---------------|
| January 2014 |
| December 2013 |
| November 2013 |
| October 2013 |
Here is a SQLFiddle demo
It is MySQL, then Use DATE_FORMAT function to fetch in a specific format for display.
SELECT
date_format(DateInterval, '%M %Y') as dates
FROM MyTable
order by
date_format( DateInterval, '%Y%m' ) desc;