Example: There is a table T1 having columns A1 and A2. A1 has integer type data and A2 has array struct. Now A2 has a column C1. What should be the syntax of the query to find the value of A1 corresponding a certain value of C1?
select distinct
A1
from T1 lateral view explode(A2) a2 as s
where a2.s.C1 = {myvalue}
Demo
with T1 as
(
select 1 as A1,array(named_struct('c1',7,'c2',1),named_struct('c1',7,'c2',8),named_struct('c1',5,'c2',2)) as A2
union all select 2 as A1,array(named_struct('c1',6,'c2',7),named_struct('c1',9,'c2',9)) as A2
union all select 3 as A1,array(named_struct('c1',7,'c2',7)) as A2
union all select 4 as A1,array(named_struct('c1',8,'c2',3),named_struct('c1',3,'c2',4)) as A2
)
select distinct
A1
from T1 lateral view explode(A2) a2 as s
where a2.s.C1 = 7
;
+----+
| a1 |
+----+
| 1 |
| 3 |
+----+
Related
I have a Table like this in Sheet1
A B
1234.jpg | c1
1234.jpg | c2
1234.jpg | c3
3456.jpg | c8
3456.jpg | c9
3456.jpg | c10
haha.jpg | c2
haha.jpg | c5
haha.jpg | c9
I need the to match the data according to the Columns in Sheet2 and the data should result something like this.
c1 c2 c3 c4 c5
123.jpg Y Y Y N N
3456.jpg N N N N N
haha.jpg N Y N N Y
I am currently only able to make out this
=IF(ISERROR(MATCH(A2,Sheet1!$A$1:$B$9,0)),"Y","N")
Which returns Y as long as A2 matches something from the array. How do I go about matching it as the Column in Sheet2? I'm open to using functions or VBA
Use following formula to D3 cell as per screenshot.
=IF(SUMPRODUCT(($A$2:$A$10=$C3)*($B$2:$B$10=D$2))=1,"Y","N")
....................................................................................................................................................... You can also use this array formula.
=IF(ISNUMBER(MATCH($C3&D$2,$A$2:$A$10&$B$2:$B$10,0)),"Y","N")
Press CTRL+SHIFT+ENTER to evaluate the formula as it is an array formula.
After entering formula as array formula, drag and drop to right and down as you need.
a1 | b1 | 0.1
a1 | b2 | 0.2
a2 | b1 | 0.3
a2 | b2 | 0.4
how to transform this table to
xx | a1 | a2
b1 | 0.1 | 0.3
b2 | 0.2 | 0.4
Make use of Pivot tables. Enter Column A as Column labels, Column B as Row Labels and Column C as Values. If values are not sum by default, change it to Sum.
Output:
You can remove the headers deselecting the Field Headers in Options tab.
You can also hide the grand totals by clicking on Options under the same tab. (Located at the left corner of the screen).
If you don't want Grand Total and other..., you can use Index:
Create a New Sheet with your Header xx, a1, a2
Copy column B b1, b2,...to the new sheet under xx
select the Data b1, b2,... in the new sheet
Remove Duplicates
Distinct and unique values will remain
Under a1 write the following formula:
=IFERROR(INDEX(Sheet1!$C$1:$C$4,MATCH(B$1&$A2,Sheet1!$A$1:$A$4&Sheet1!$B$1:$B$4,0)),"")
Array Formula press Ctrl+Shift+Enter at the same time instead of Enter
and drag it in the same row and down in columns
Change A1:A4, B1:B4 and C1:C4 to correspond your last row of Data but keep $ for fixed references
I want to do this:
A | B
===================
'blank' | 1
12 | 4
'blank' | 2
13 | 'blank'
I want to check B column and if there is a number there ( any number ) ,then fill the corresponding A cell (but only blank(empty) A cells ) with zero value.
I am trying something like this:
=IF( ISNUMBER(B1:B4) AND ( IF( NOT(ISNUMBER(A1:A4) ) ) ); (A1:A4 = 0);"" )
but it doesn't work.( I have set to the else statement above the "" )
If you are happy to write formula in new column then use this formula in column C for every cell C1=IF(AND(ISNUMBER(B1),A1=""),0,A1) then drag this formula for C2, C3, C4 etc.,.
my example
I will try to be as clear and concise as possible. I am working on a spreadsheet in which I have item prices listed in a range of A1:A40. B1:B40 lists a numerical digit (either 1, 2, 3, etc.) that corresponds with a purchase category type (groceries, gas, etc.). Now I want one cell, such as C1, to add all instances in the A range that equal a specific number in B.
For example:
A1 = $5.00 | B1 = 1 | C1 = The sum in range A1:A3 if it's corresponding B value is equal to 1 (In this case B1 and B3, so C1=A1+A3)
A2 = $2.50 | B2 = 2 | C2 = The sum in range A1:A3 if it's corresponding B value is equal to 2 (In this case B2, so C2= B2)
A3 = $4.00 | B3 = 1 | C3 =
Use SUMIF Function
SUMIF(range, criteria, [sum_range])
In Cell C1 enter the formula = SUMIF(B:B,1,A:A)
I have a list of dates in B2:GF2. I enter 2 dates - "A1 start date and B1 End date". I also enter a value (number) in cell C1. The value in C1 should be copied to all the cells under the list of dates from A2:GF2 between the dates choosed in A1 and B1. Let the copied value between the row A3:GF3.
E.g.:
A | B | C
Row1 3/3/2015| 5/5/2015 | ABC
Row2 2/2/2015 | 3/3/2015 | 4/4/2015 | 4/23/2015 | 5/5/2015....
ABC ABC ABC ABC
In cell C4, type =IF(AND(C3>=$A$2,C3<$B$2),$C$2,""), then just copy cell C4 across.