我有两个表,一个有9个字段,另一个有teradata sql中的12个字段。虽然我可以加入9个常见字段,但3个字段未加入,因此创建了重复读取。
[Join on t1.field1=t2.field1
And t1.field2=t2.field2
And t1.field3=t2.field3
And t1.field4=t2.field4
And t1.field5=t2.field5
And t1.field6=t2.field6
And t1.field7=t2.field7
And t1.field8=t2.field8
And t1.field9=t2.field9]
但我还有3个字段t2.field10
,t2.field11
,t2.field12
这是从table1
创建重复记录。
您能否建议如何构建一个不会从table1
创建记录副本的select语句?
表1
<tr> <th> semester </th><th> country </th><th> state </th><th> county </th><th> city </th><th> school name </th><th> type </th><th> type2 </th><th> class </th><th> number of students </th> </tr>
<tr> <td> spring2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 1 </td><td> 331 </td> </tr>
<tr> <td> spring2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 2 </td><td> 487 </td> </tr>
<tr> <td> spring2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 3 </td><td> 329 </td> </tr>
<tr> <td> spring2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 4 </td><td> 400 </td> </tr>
<tr> <td> spring2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 5 </td><td> 225 </td> </tr>
<tr> <td> fall2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 1 </td><td> 249 </td> </tr>
<tr> <td> fall2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 2 </td><td> 136 </td> </tr>
<tr> <td> fall2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 3 </td><td> 140 </td> </tr>
<tr> <td> fall2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 4 </td><td> 444 </td> </tr>
<tr> <td> fall2016 </td><td> USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 5 </td><td> 371 </td> </tr>
表2:
country </th><th> state </th><th> county </th><th> city </th><th> school name </th><th> type </th><th> type2 </th><th> level </th><th> class </th><th> homework </th><th> field trip </th><th> tests </th><th> planned budget </th><th> actual budget </th> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 1 </td><td> american literature </td><td> n </td><td> n </td><td> 8 </td><td> 6856 </td><td> 5800.357992 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 1 </td><td> geography </td><td> y </td><td> y </td><td> 8 </td><td> 3040 </td><td> 963.4004114 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 1 </td><td> music </td><td> y </td><td> y </td><td> 10 </td><td> 3288 </td><td> 2362.845994 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 2 </td><td> american literature </td><td> n </td><td> n </td><td> 8 </td><td> 6984 </td><td> 4368.417857 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 2 </td><td> british literature </td><td> n </td><td> n </td><td> 4 </td><td> 3977 </td><td> 3861.683941 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 2 </td><td> geography </td><td> y </td><td> n </td><td> 5 </td><td> 5358 </td><td> 1727.575547 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 3 </td><td> biology </td><td> y </td><td> n </td><td> 6 </td><td> 4490 </td><td> 4241.514602 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 3 </td><td> british literature </td><td> n </td><td> y </td><td> 9 </td><td> 3476 </td><td> 2176.995858 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 3 </td><td> PE </td><td> y </td><td> y </td><td> 7 </td><td> 6060 </td><td> 713.4806136 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 4 </td><td> biology </td><td> y </td><td> y </td><td> 8 </td><td> 5059 </td><td> 2269.706168 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 4 </td><td> music </td><td> n </td><td> y </td><td> 8 </td><td> 3250 </td><td> 583.2956503 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 4 </td><td> PE </td><td> n </td><td> y </td><td> 3 </td><td> 3945 </td><td> 577.6461806 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 5 </td><td> american literature </td><td> n </td><td> y </td><td> 7 </td><td> 4083 </td><td> 2853.53736 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 5 </td><td> music </td><td> y </td><td> y </td><td> 8 </td><td> 3502 </td><td> 1257.361273 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 5 </td><td> PE </td><td> n </td><td> n </td><td> 3 </td><td> 5234 </td><td> 4075.859156 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 1 </td><td> american literature </td><td> n </td><td> n </td><td> 8 </td><td> 6856 </td><td> 5800.357992 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 1 </td><td> geography </td><td> y </td><td> y </td><td> 8 </td><td> 3040 </td><td> 963.4004114 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 1 </td><td> music </td><td> y </td><td> y </td><td> 10 </td><td> 3288 </td><td> 2362.845994 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 2 </td><td> american literature </td><td> n </td><td> n </td><td> 8 </td><td> 6984 </td><td> 4368.417857 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 2 </td><td> british literature </td><td> n </td><td> n </td><td> 4 </td><td> 3977 </td><td> 3861.683941 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 2 </td><td> geography </td><td> y </td><td> n </td><td> 5 </td><td> 5358 </td><td> 1727.575547 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 3 </td><td> biology </td><td> y </td><td> n </td><td> 6 </td><td> 4490 </td><td> 4241.514602 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 3 </td><td> british literature </td><td> n </td><td> y </td><td> 9 </td><td> 3476 </td><td> 2176.995858 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 3 </td><td> PE </td><td> y </td><td> y </td><td> 7 </td><td> 6060 </td><td> 713.4806136 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 4 </td><td> biology </td><td> y </td><td> y </td><td> 8 </td><td> 5059 </td><td> 2269.706168 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 4 </td><td> music </td><td> n </td><td> y </td><td> 8 </td><td> 3250 </td><td> 583.2956503 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 4 </td><td> PE </td><td> n </td><td> y </td><td> 3 </td><td> 3945 </td><td> 577.6461806 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 5 </td><td> american literature </td><td> n </td><td> y </td><td> 7 </td><td> 4083 </td><td> 2853.53736 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 5 </td><td> music </td><td> y </td><td> y </td><td> 8 </td><td> 3502 </td><td> 1257.361273 </td> </tr>
USA </td><td> Illinois </td><td> Cook </td><td> Chicago </td><td> x1 </td><td> elementary </td><td> public </td><td> 5 </td><td> PE </td><td> n </td><td> n </td><td> 3 </td><td> 5234 </td><td> 4075.859156 </td> </tr>
表3输出应如下所示:
</th><th> type </th><th> type2 </th><th> level </th><th> number of students </th><th> class </th><th> homework </th><th> number of teachers </th><th> tests </th><th> planned budget </th><th> actual budget </th><th> tests/student </th><th> $planed per student </th><th> actual $/student </th> </tr>
然而,我运行的每个查询都会得到重复数量的学生,而不是超过计数#students / teacher或计划$ / student,实际$ / student。
如果我要根据这三个维度进行过滤,我需要这样做: -类 -tests -homework
的 - #教师/学生 - 实际$ /学生 -planned $ /学生
应该是每班学生的最低顺序
我试图转置桌面2上的3个字段,但问题是当我将其插入画面时,我无法正确过滤它们。