由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - SQL check likeness between two large tables (转载)
相关主题
SQL combine two tables into one table and add a new columncopy database from one server to another in IBM netezza Aginity workbench
Error of SQL query on IBM netezza SQL database from Aginity workbench请教一道算法题目,请高手指点
check time table created in IBM SQL Aginity workbench ? (转载)sql的2个问题
求教一个SQL的问题error of sql query in MS Access database
sort two same tables SQL but different results (转载)贴几个job opening (转载)
SQL copy a table into a new table and add a new column (转载)pypyodbc error access netezza SQL server on win7 (转载)
error of executing SQL query of string concatenation (转载被一个面试题卡的泪流满面 SQL
add column name in exporting table netezza aginity sql (转载)SQL add some columns into a table from another table
相关话题的讨论汇总
话题: table2话题: table1话题: sql话题: id2话题: id1
进入JobHunting版参与讨论
1 (共1页)
l******9
发帖数: 579
1
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: SQL check likeness between two large tables
发信站: BBS 未名空间站 (Tue May 6 15:38:29 2014, 美东)
I need to check the likeness between two data tables on SQL. I am working on
Aginity Workbench for Netezza on Win 7.
The tables are very large. One of them has 100 million rows and 4 columns;
another one has 1500 million rows and 3 columns.
Example, table1
ID1 ID2 ID3 Value
xxxx xxxxxx xxxxxxxx xxx.xxxxxx // here x is 0-9 int
table2:
ID1 ID2 Value
xxxx xxxxxx xxx.xxxxxx
the ID1 and ID2 may be duplicated but Values are not duplicated in the same
table.
I need to check whether table1 is a subset of table2 and find the rows that
are avaialble in table1 but not in table2 and vice versa.
I am new to SQL. How to design the efficient SQL queries ? I need to do the
same tasks frequently, so en efficient query may be more helpful.
I use this method :
SELECT * FROM table1 a
WHERE NOT EXISTS (
SELECT table2.ID1
FROM table2 b
WHERE b.ID1 = a.ID1
AND b.ID2 = a.ID2)
But, the results are 0 rows. I also checked that there are no duplicated
rows in the two tables. Why table2 is much larger than table1 ?
Are there other ways to find their differences ?
Thanks
F*******2
发帖数: 371
2
你code得到的是在table1 但是不在table2里面的数据
用下面code可以得到不在A B inner join中的数据:
SELECT A.ID1 AS A_ID1, A.ID2 AS A_ID2, A.ID3 as A_ID3, A.Value AS A_Value,
B.Value AS B_Value, B.ID1 AS B_ID1,B.ID2 AS B_ID2
FROM Table1 AS A
FULL OUTER JOIN Table2 AS B
ON A.ID1 = B.ID1 and A.ID2=B.ID2
WHERE A.ID1 IS NULL
OR B.ID1 IS NULL
Check here:
http://www.codeproject.com/Articles/33052/Visual-Representation
F*******2
发帖数: 371
3
还有看table1和table2中ID1 ID2 的format是否一致
1 (共1页)
进入JobHunting版参与讨论
相关主题
SQL add some columns into a table from another tablesort two same tables SQL but different results (转载)
error export sql table from IBM netezza database to a fileSQL copy a table into a new table and add a new column (转载)
一道面筋题目~error of executing SQL query of string concatenation (转载
报面筋求实习合租add column name in exporting table netezza aginity sql (转载)
SQL combine two tables into one table and add a new columncopy database from one server to another in IBM netezza Aginity workbench
Error of SQL query on IBM netezza SQL database from Aginity workbench请教一道算法题目,请高手指点
check time table created in IBM SQL Aginity workbench ? (转载)sql的2个问题
求教一个SQL的问题error of sql query in MS Access database
相关话题的讨论汇总
话题: table2话题: table1话题: sql话题: id2话题: id1