I'm trying to select rows in between two values using big query.
Here the table is:
ID Group values
1 A 10I
1 B 20I
1 C 30I
1 D 40I
1 E 50I
1 F 60I
1 G 70I
1 H 80I
1 I 90I
Here I need to select rows from Group C to G.
The code i'm using is:
select * from data
where Group >= 'C' and Group <='G'
The above code gave no results.
Also i tried:
select * from data
where Group between 'C' and 'G'
This also returned no results.
Someone please provide a solution.
This is because "Group" is a reserved word (the GROUP BY): BQ expects you to group something and didn't understand that here it is the name of a column. To make BQ understand just as backslashes:
SELECT *
FROM data
WHERE `Group` BETWEEN "C" AND "G"
Related
I have table where source has 1 column, like below. for example, column name is A and I have set of records in the source.
A
1
1
1
2
2
3
I want to populate two columns in target, Say columns are A and B.
Column A in the Target has same values as in source and column B has count
A B
1 1
1 2
1 3
2 1
2 2
3 1
Can someone please explain how can i achieve this.
Thanks in advance
If source is a dbms like oracle, you can use source qualifier overwrite sql like below. Use row number and partition by to generate sequence for every A.
Select
A, row_number() over(partition by A order by A) as B
From mytable
If you're looking for infomatica only solution then this is how you can do it.
Sort the data by column A
Use ex transformation, create one in/out two var, and one out port.
We are going to compare first val with prev val, if they r same, add 1to the sequence else start from 1 again.
A in/out
v_B = iif (A=prev_A, v_B +1, 1)
prev_A=A
o_B =v_B
Link A and o_B to the target.
I am working with data from a data cube, meaning I cannot easily control the structures of my underlying data. My underlying data looks like the below. As a Cube datasource, each one of these columns also is its own table with define join relationships between one another. For example, to select the Group1 column on its own would look like 'Group1'[Group1].
Group 1
Group2
Group3
Desired Column
1
a
x
1
2
a
y
1
3
a
y
1
4
b
y
1
5
b
y
1
6
c
z
0
I am trying to create a variable that reflects what is shown in "Desired Column" so that I can include results for any value of Group2 that matches to the "y" value of Group3.
I am not very fluent with DAX, but my preliminary thoughts on an approach are to run a FILTER on Group3 for "y", select values of Group2, and then somehow use those Group2 values in a CONTAINS statement in a further FILTER. Here is my current, non-functional attempt:
Is_Y = CONTAINS(NATURALLEFTOUTERJOIN('Group2','Group3'), 'Group3'[Group3], "Y")
I've 2 cols lets say id and values. I want to concatenate values grouped by id col.
for eg.
I've
ID Values
1 a
1 b
2 a
2 b
I need the output as
ID Values
1 a,b
2 a,b
You can use an array_agg followed by an array_join
select id, array_join(array_agg(values),',') from table group by 1
The array_agg will give you an array of all values with the same id, and the array_join will concatenate them into a string. See the docs.
I am trying to run а query against several ranges combined with {} like query({A2:C5, if(C1:C5='something',1,0)}, "select ..."). But I am getting an #REF! error with a message Function ARRAY_ROW parameter 2 has mismatched row size. Expected: 4. Actual: 1. What is the reason for that?
Here is a detailed example. Suppose I have a table like that:
id kind color
1 a green
2 a green
3 b green
4 c blue
I want to get a table showing number of cells with green for each kind:
kind color_count
a 2
b 1
c 0
Initially, I tried a query with the where clause for that:
=query(A2:C5, "select B, count(C) where C='green' group by B", -1)
But that does not include the row with zero values. So I tried to add an extra column with values 1 for the green color and 0 otherwise and use SUM over that without the where clause:
=query({A2:C5, if(C2:C5="green", 1, 0)}, "select B, sum(D) group by B", -1)
but that gives the above $REF!
As a workaround I added a column D to the table with the formula
=arrayformula(if(C2:C5="green", 1, 0))
Then the following query works and gives the desired result:
=query(A2:D5, "select B, sum(D) group by B", -1)
But is it possible to avoid this artificial column?
IF returns only 1 cell unless you use ARRAYFORMULA. so the error is on a spot because you have 4 cells on one side and 1 cell on the other side.
try:
=ARRAYFORMULA(QUERY({B:B, IF(C:C="green", 1, 0)},
"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label sum(Col2)''", 0))
I am trying to generate a list using M Query, but instead of generating a list starting from a specific, number, I want the number to start at 1 and then add 1 for every row on another table.
So for example, if I have:
Tbl1
Col1
A
B
C
D
D
I want to generate
Tbl2
Col1
1
2
3
4
5
I want the number to start at 1 and then add 1 for every row on another table.
if I understand your correctly, here it is:
={1..Table.RowCount(Tab1)}