Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
进行SQL查询_Sql_Hive - Fatal编程技术网

进行SQL查询

进行SQL查询,sql,hive,Sql,Hive,输入数据 +---------+----------------+-----------+-----------------+--------------+------+ | country | tgtschema_name | tablename | tgttableversion | col_function | flag | +---------+----------------+-----------+-----------------+--------------+------+ |

输入数据

+---------+----------------+-----------+-----------------+--------------+------+
| country | tgtschema_name | tablename | tgttableversion | col_function | flag |
+---------+----------------+-----------+-----------------+--------------+------+
| zz      | abc_zz         | table1    | 01              | TBD1         | no   |
+---------+----------------+-----------+-----------------+--------------+------+
| bs      | abc_bs         | table2    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| bs      | abc_bs         | table3    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| bs      | abc_bs         | table4    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| bs      | abc_bs         | table4    | 02              | TBD2         | no   |
+---------+----------------+-----------+-----------------+--------------+------+
| do      | abc_do         | table5    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| do      | abc_do         | table6    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| do      | abc_do         | table7    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
输出所需数据

+---------+----------------+-----------+-----------------+--------------+------+
| country | tgtschema_name | tablename | tgttableversion | col_function | flag |
+---------+----------------+-----------+-----------------+--------------+------+
| zz      | abc_zz         | table1    | 01              | TBD1         | no   |
+---------+----------------+-----------+-----------------+--------------+------+
| bs      | abc_bs         | table2    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| bs      | abc_bs         | table3    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| bs      | abc_bs         | table4    | 02              | TBD2         | no   |
+---------+----------------+-----------+-----------------+--------------+------+
| do      | abc_do         | table5    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| do      | abc_do         | table6    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+
| do      | abc_do         | table7    | 01              | TBD1         | yes  |
+---------+----------------+-----------+-----------------+--------------+------+

如果我在country、tgtschema_name和tablename列中有多个记录,那么我需要有一个标记为“否”的记录。

编辑:答案是在不知道具体数据库的情况下提供的

假设您具有id字段,则类似于此的内容应该可以工作:

select * 
from t t1 
where not exists (
  select country 
  from t t2 
  where t1.id != t2.id
     t1.country = t2.country and 
     (...add the rest here...) and 
     t2.flag = 'No'
)

其思想是,除了第二个条目具有相同属性外,您可以通过标记“否”来获取所有数据。您希望省略另一个条目。

其配置单元数据库我在输入中包含了一个ID(序列号)列。执行后,我遇到以下错误:“第6:8行不支持的子查询表达式'id':子查询表达式同时引用父表达式和子查询表达式,并且不是有效的联接条件。”我不确定如何使用配置单元,因为它提供了HiveQL,但也许你可以让左连接并排除那些不存在的元素不起作用的元素?