#!/bin/sh
for date in 20161025 20161027 20161028 20161102 20161103 20161104 20161105
do
echo "${date}"
done
假设有tableA和tableB 两张表,Table A是左边的表,Table B是右边的表。
其各有四条记录,其中有两条记录是相同的,如下所示:
id name id name
-- ---- -- ----
1 Pirate 1 Rutabaga
2 Monkey 2 Pirate
3 Ninja 3 Darth Vader
4 Spaghetti 4 Ninja
SELECT * FROM TableA INNER JOIN TableB
ON TableA.name = TableB.name
id name id name
-- ---- -- ----
1 Pirate 2 Pirate
3 Ninja 4 Ninja
SELECT * FROM TableA FULL OUTER JOIN TableB
ON TableA.name = TableB.name
id name id name
-- ---- -- ----
1 Pirate 2 Pirate
2 Monkey null null
3 Ninja 4 Ninja
4 Spaghetti null null
null null 1 Rutabaga
null null 3 Darth Vader
Full outer join 产生A和B的并集。但是需要注意的是,对于没有匹配的记录,则会以null做为值。
`
SELECT * FROM TableA FULL OUTER JOIN TableB ON TableA.name = TableB.name WHERE TableA.id IS null OR TableB.id IS null
id name id name
-- ---- -- ----
2 Monkey null null
4 Spaghetti null null
null null 1 Rutabaga
null null 3 Darth Vader
SELECT * FROM TableA LEFT OUTER JOIN TableB ON TableA.name = TableB.name
id name id name
-- ---- -- ----
1 Pirate 2 Pirate
2 Monkey null null
3 Ninja 4 Ninja
4 Spaghetti null null
Left outer join 产生表A的完全集,而B表中匹配的则有值,没有匹配的则以null值取代。
SELECT * FROM TableA LEFT OUTER JOIN TableB ON TableA.name = TableB.name WHERE TableB.id IS null
id name id name
-- ---- -- ----
2 Monkey null null
4 Spaghetti null null
几个表之间关键字的连续join,得到需要查找的交叉信息。
select t1.deviceid as deviceid ,t3.site_telephone as telephone ,t4.*
from
DB1.table1 t1
join DB2. table2 t2 on (t1.deviceid = t2.deviceid)
join DB3.table3 t3 on (t2.mobile=t3.telephone)
join DB1.table4 t4 on (t3.user_no=t4.user_id);
其中的index,是按照正则字符串()的位置
1. 语法: regexp_extract(string subject, string pattern, int index)
2. 返回值: string
3. 说明:将字符串subject按照pattern正则表达式的规则拆分,返回index指定的字符。注意,在有些情况下要使用转义字符
4. 举例:
5. hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 1) from dual;
6. the
7. hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 2) from dual;
8. bar
9. hive> select regexp_extract(‘foothebar’, ‘foo(.*?)(bar)’, 0) from dual;
10. foothebar
匹配手机号码:
select count(*) from DB1.user_info_table
where length(regexp_extract(telephone, '(1[0-9]{10})', 1))=11;