I got a table in this format
Name Datum
A 01.01.2019
B 17.03.2020
C 18.03.2020
C 01.04.2020
I get this table output from this query:
=QUERY(Anrufe!$1:$1000;"Select A,B where A is not null ORDER BY B ASC label A 'Name', B 'Datum'")
I am trying to change the query, so that it performs a group by. This is what it should look like
Name Datum count
A 01.01.2019 1
B 17.03.2020 1
C 01.04.2020 2
But when i add a group by and add a aggregation function to the select it still throws an error.
=QUERY(Anrufe!$1:$1000;"Select A,B, min(B) where A is not null group by A ORDER BY B ASC label A 'Name', B 'Datum'")
I want the query to choose the youngest Date, that is in the column B. But it seems that the QUERY-Parser forces me to add the column B to the group by. This results in the same problem, that i manually have to count the records with the same names.
Anyone has any idea how to solve that?
Already checked those links:
Google sheets query order by SUM
Google Sheets Query: Possible to Group / Order by without Select?
Google Sheets query - Multiple “where” conditions with “group by” and “order by”
I got this message (CANNOT_GROUP_WITHOUT_AGG) from a simple query
I think you want this:
=QUERY(Anrufe!$1:$1000,"Select A,min(B),count(A) where A is not null group by A ORDER BY min(B) ASC label A 'Name', min(B) 'Datum'")
Related
I'm trying to get typeorm to generate a select query with group by clause, in which the parameters of the group by clause references the column in the select clause using its numeric order number:
SELECT SUBSTRING(A, 1, LENGTH(A)), some_expression(B), DISTINCT C
FROM table
GROUP BY 1, 2
Instead of
SELECT SUBSTRING(A, 1, LENGTH(A)), some_expression(B), DISTINCT C
FROM table
GROUP BY SUBSTRING(A, 1, LENGTH(A)), some_expression(B)
Is there an elegant way to do this? I'm using the QueryBuilder API to generate a sql query which is then used for some other purpose.
I try to find a solution to merge different row and add some cells at the same time.
This is a simplified example :
In this example I would like to be able to generate this for the name of "Robin Decoster"
As the name (Robin Decoster) AND the project name is the same (Grand Nord) I would like to do a sum on column E and on column F to simplify the data base.
I thought to use query methode with :
=QUERY(BD!A1:GF6;"SELECT B, sum(E), sum(F) where D='Grand Nord' AND B='Robin Decoster' GROUP BY B")
It could works but I can't display the other Columns (AVS, Adresse, Projet Films).
Any Idea ?
try:
=QUERY(BD!A1:GF6;
"select B,C,D,sum(E),sum(F)
where D='Grand Nord'
and B='Robin Decoster'
group by B,C,D")
I'm using a QUERY function in Google Sheets. I have a named data range ("Contributions" in table on another sheet) that consists of many columns, but I'm only concerned with two of them. For simplicity sake, it looks something like this:
I have another table that contains the unique set of names (e.g.: "Fred", "Ginger", etc. each only once) and I want to extract the level # (column B) from the above table to insert the most recent (largest number) in this second table.
Right now, my query looks like this:
=QUERY(Contributions, "select B,C where C='"&A5&"' order by B desc limit 1",1)
The problem is, that it outputs both B & C data - e.g.:
11 Fred
But since I already have the name (in column A of this other table) I only want it to output the value from B - e.g.:
11
Is there a way to output only a subset (in this case 1 of 2) of the columns of output based on a directive within the query itself (as opposed to doing post-processing of the results)?
Outputting a Subset of Columns Used in Query
In order to output only certain columns of a query result, the query only needs to select the columns to be displayed while the constraints / conditions may utilize other columns of data.
For example (as an answer to my own question) - I have a table like this:
I needed to get the data from the row with a name matching another cell (on another sheet) and with the latest (largest) number - but I only want to output the number part.
My initial attempt was:
=QUERY(Contributions, "select B,C where C='"&A5&"' order by B desc limit 1",1)
But that output both B & C where I only wanted B. The answer (thanks to # Calculuswhiz) was to continue using C for the condition but only select on B:
=QUERY(Contributions, "select B where C='"&A5&"' order by B desc limit 1",1)
I have the following query:
SELECT sum("field1" * "field2") FROM "my_db"."autogen"."data" GROUP BY time(1d) FILL(null)
In short I would like to perform the operation sum on the product of two fields field and field2.
The above query returns an error: expected field argument in sum().
Is this kind of thing at all possible in InfluxDB?
Here's a idea: try Sub Query
Note:I don't have editor right now so it might give error too
SELECT SUM(Multiplication) FROM
(SELECT "field1" * "field2" as Multiplication, time(1d) as Days FROM
"my_db"."autogen"."data" GROUP BY time(1d) FILL(null)
) GROUP BY Days
I have a hive table A with 5 columns, the first column(A.key) is the key and I want to keep all 5 columns. I want to select 2 columns from B, say B.key1 and B.key2 and 2 columns from C, say C.key1 and C.key2. I want to join these columns with A.key = B.key1 and B.key2 = C.key1
What I want is a new external table D that has the following columns. B.key2 and C.key2 values should be given NULL if no matching happened.
A.key, A_col1, A_col2, A_col3, A_col4, B.key2, C.key2
What should be the correct hive query command? I got a max split error for my initial try.
Does this work?
create external table D as
select A.key, A.col1, A.col2, A.col3, A.col4, B.key2, C.key2
from A left outer join B on A.key = B.key1 left outer join C on A.key = C.key2;
If not, could you post more info about the "max split error" you mentioned? Copy+paste specific error message text is good.