9、Join
Let's look at inner join
Check two table
If you didn't specify "EMPID" select from which table the system will throw an error message
column ambiguously defined: EMPID
10、UNIONS
Check table data Firstly
Now we union EMPID field data from two table
If you don't want to delete the duplicate data, you can use : union all
11、Filter data by having
select "HANA04"."EMPFACT1".empid as ID,
sum(sal) as total
from "HANA04"."EMPFACT1","HANA04"."EMPFACT2"
where "HANA04"."EMPFACT1"."EMPID" = "HANA04"."EMPFACT2"."EMPID"
group by "HANA04"."EMPFACT1".empid
How can we only get data which total not lower than 9999?
select "HANA04"."EMPFACT1".empid as ID,
sum(sal) as total
from "HANA04"."EMPFACT1","HANA04"."EMPFACT2"
where "HANA04"."EMPFACT1"."EMPID" = "HANA04"."EMPFACT2"."EMPID"
group by "HANA04"."EMPFACT1".empid
having sum(sal) > 9999
12、SUB-SELECTS
select
"HANA04"."EMPFACT1".empid ,
"HANA04"."EMPFACT2".deptname,
avg("HANA04"."EMPFACT1".sal)
from "HANA04"."EMPFACT1","HANA04"."EMPFACT2"
where "HANA04"."EMPFACT2".empid = "HANA04"."EMPFACT1".empid
group by "HANA04"."EMPFACT1".empid,deptname
Add having filter
select
"HANA04"."EMPFACT1".empid ,
"HANA04"."EMPFACT2".deptname,
avg("HANA04"."EMPFACT1".sal)
from "HANA04"."EMPFACT1","HANA04"."EMPFACT2"
where "HANA04"."EMPFACT2".empid = "HANA04"."EMPFACT1".empid
group by "HANA04"."EMPFACT1".empid,deptname
having avg("HANA04"."EMPFACT1".sal) >
(
select avg(sal) from "HANA04"."EMPFACT1"
)
13、Array data
create column table tab1
(
col1 int primary key,
col2 int array
);
insert into tab1 values
(
4, array ( 1,2,3,4 )
);
insert into tab1 values
(
5, array ( 11,22,33,44 )
);
Update data
upsert tab1 values
(
4,array ( 12,13,11,15 )
)
where col1 = 4
select
col1 ,
col2[1],
col2[2],
col2[3],
col2[4]
from tab1
Get array count
insert into tab1 values
(
1,array ( 1,2,3,4,5 )
);
insert into tab1 values
(
2,array ( 1,2,3,4,5,6 )
);
select
cardinality(col2)
from tab1
order by col1
Get array data and ordinality
Insert
insert into tab1 values
(
6,array(20,21,22)||array(23,24,25,26,27,null,29,null)
);
insert into tab1 values
(
7,array(20,21,22,23,24,25,26,27,null,29,null)
)
Check data
select
col1 ,
col2[1],
col2[2],
col2[3],
col2[4],
col2[5],
col2[6],
col2[7],
col2[8],
col2[9],
col2[10],
col2[11]
from tab1
where col1 > 5