求循环Sql语句,请高手帮忙解决,非常谢谢!
问题描述:每一组中两个表的结构完全相同,只是表的名字不同,例如:t1和tt1是一组,t2和tt2是一组,依次类推...。
有表结构如下
t1 tt1
sup varchar sup varchar
it1 varchar it1 varchar
-----------------------
t2 tt2
sup varchar sup varchar
it1 varchar it1 varchar
it2 varchar it2 varchar
-----------------------
t3 tt3
sup varchar sup varchar
it1 varchar it1 varchar
it2 varchar it2 varchar
it3 varchar it3 varchar
-----------------------
也就是我想用循环语句实现如下三条语句:
select t1.it1,tt1.it1 as lt2 from t1,tt1 where t1.it1 <tt1.it1 order by t1.it1
select t2.it1,t2.it2,tt2.it2 as it3 from t2,tt2 where t2.it1 = tt2.it1 and t2.it2 <tt.it2 order by t2.it1
select t3.it1,t3.it2,tt3.it3 as it4 from t3,tt3 where t3.it1 = tt3.it1 and t3.it2=tt3.it2 and t3.it3 <tt3.it3