I want to get the weather information for a specific location.
Right now, I need to calls to get them: The first one translated my current position (lat/lon) to a WOEID, the second call retrieves the Weather information by using that WOEID.
Can I combine those 2 queries?
The first one is:
select * from yahoo.maps.findLocation where q="LAT, LON" and gflags="R"
The second one is:
select * from weather.bylocation where location= WOEID AND unit = 'c'
You can use sub-selects to join data between different queries.
In your case, you can grab the woeid from the yahoo.maps.findLocation table and insert that into a query against the weather.bylocation table as follows:
select *
from weather.bylocation
where unit = 'c' and location in (
select Results.woeid
from yahoo.maps.findLocation
where q="LAT, LON" and gflags="R"
limit 1
)
Related
I am using Google Sheets and have a connected query where I am using parameters. When one of the parameters is configured to be a subquery, the query will run, but no results are returned.
For example, here is my (simplified) query:
SELECT *
FROM table
WHERE campaign IN (#CAMPAIGN);
In this example, I have the #CAMPAIGN parameter in the Google Sheet configured as:
SELECT DISTINCT campaign FROM table2
If I manually substitute the parameter in the BQ console, it runs fine and returns the expected results. Is there a reason this functionality does not work with parameter substitution in the Google Sheet? Is there a way around this?
Depending on how much SQL SELECT type lookups you do, it may help to use a #customfunction that I wrote. You need to place my SQL .js in your Google sheets project and the =gsSQL() custom function will be available.
The one requirement for this versus using =QUERY() is that unique column titles are required for each column.
It is available on github:
gsSQL github project
This example works if each sheet is a table, so it would be entered something like
=gsSQL("SELECT books.id, books.title, books.author_id
FROM books
WHERE books.author_id IN (SELECT id from authors)
ORDER BY books.title")
In this example, I have a sheet named 'books' and another sheet named 'authors'.
If you need to specify a named range or an A1 notation range as a table, this can also be done with a little more work...
=gsSQL("SELECT books.id, books.title, books.author_id
FROM books
WHERE books.author_id IN (SELECT id from authors)
ORDER BY books.title", {{'books', 'books!$A$1:$I', 60};
{'authors', 'authors!$A$1:$J30', 60}}, true)
In this example, the books and authors come from specific ranges, the data will be cached for 60 seconds and column titles are output.
I have an Esper query that returns multiple rows, but I'd like to instead get one row, where that row has a list (or concatenated string) of all of the values from the (corresponding columns of the) matching rows that my current query returns.
For example:
SELECT Name, avg(latency) as avgLatency
FROM MyStream.win:time(5 min)
GROUP BY Name
HAVING avgLatency / 1000 > 60
OUTPUT last every 5 min
Returns:
Name avgLatency
---- ----------
A 65
B 70
C 75
What I'd really like:
Name
----
{A, B, C}
Is this possible to do via the query itself? I tried to make this work using subqueries, but I'm not working with multiple streams. I can't find any aggregation functions or enumeration functions in the Esper documentation that fits what I'm trying to do either.
Thanks to anybody that has any insight or direction for me here.
EDIT:
If this can't be done via the query, I'm open to changing the subscriber, or anything else, if necessary.
You can have a subscriber or listener do the concat. There is a "Multi-Row Delivery" for subscribers. Or use a table like below.
// create table to hold aggregation result
create table LatencyTable(name string primary key, avgLatency avg(double));
// update aggregations in table from events coming in
into LatencyTable select name, avg(latency) as avgLatency from MyStream#time(5 min) group by name;
// do a select with the "aggregate" enumeration method
select (select * from LatencyTable where avgLatency > x).aggregate(....) from pattern[every timer:interval(5 min)]
I have a sqlite database that I'm trying to build a query. The table column I need to retrieve is iEDLID from the table below :
Right now all I have to go on is a known iEventID from the table below :
And the the nClientLocationID from the table below.
So the requirements are I need to get current iEDLID to write, lookup from tblEventDateLocations for dEventDate and the tblLocation.nClientLocationID based on the tblLocations.iLocationID I already have and event selected on this screen.
So I would need a query that does a "SELECT DISTINCT table EventDateLocations.iEDLID FROM tblEventDateLocations ...."
So basically from another query I have the iEventID I need, and I have the event ID i need but where the dEventDate=(select date('now')) I need to retrieve the iEventDateID from table EventDates.iEventDateID to use on the table EventDateLocations
this is the point where I'm trying to wrap my head around the joins for this query and the syntax...
It seems like you want this:
select distinct edl.iEDLDID
from
tblEventDateLocations edl
join tblEventDates ed on edl.EventDateId = ed.EventDateId
where
ed.EventId = ?
and ed.dEventDate = date('now')
and edl.nClientLocationID = ?
where the ? of course represent the known event ID and location ID parameters.
Since nClientLocationId appears on table tblEventDateLocations you do not need to join table tblLocations unless you want to filter out results whose location ID does not appear in that table.
I am using following query to retrieve a single record from the ymail.messages table -
select message from ymail.msgcontent where (fid,mids) in (select folder.folderInfo.fid,
mid from ymail.messages where query="Yahoo" and mid="-----" limit 1)
but I am not able to get a single record instead of that I am getting bunch of records.
what modifications in above query will get a single record?
Change to:
select message
from ymail.msgcontent
where (fid,mids) in (
select folder.folderInfo.fid, mid
from ymail.messages
where query="Yahoo" and mid="-----" | truncate(count=1))
I have two tables - tool_downloads and tool_configurations. I am trying to retrieve the most recent build date for each tool in my database. The layout of the DB is simple. One table called tool_downloads keeps track of when a tool is downloaded. Another table is called tool_configurations and stores the actual data about the tool. They are linked together by the tool_conf_id.
If I run the following query which omits dates, I get back 200 records.
SELECT DISTINCT a.tool_conf_id, b.tool_conf_id
FROM tool_downloads a
JOIN tool_configurations b
ON a.tool_conf_id = b.tool_conf_id
ORDER BY a.tool_conf_id
When I try to add in date information I get back hundreds of thousands of records! Here is the query that fails horribly.
SELECT DISTINCT a.tool_conf_id, max(a.configured_date) as config_date, b.configuration_name
FROM tool_downloads a
JOIN tool_configurations b
ON a.tool_conf_id = b.tool_conf_id
ORDER BY a.tool_conf_id
I know the problem has something to do with group-bys/aggregate data and joins. I can't really search google since I don't know the name of the problem I'm encountering. Any help would be appreciated.
Solution is:
SELECT b.tool_conf_id, b.configuration_name, max(a.configured_date) as config_date
FROM tool_downloads a
JOIN tool_configurations b
ON a.tool_conf_id = b.tool_conf_id
GROUP BY b.tool_conf_id, b.configuration_name