存在两表main,db
表的结构:
main:
id level rate
2007 1 20
2008 1 30
表DB的结果
db:
id one two
2007 1 3
2007 2 4
2007 5 1
2008 2 5
2008 4 5
我想取出这样的数据:(只取出db中one,two 中都大于1的一条数据)
id level one two
2007 1 1 3 (剩下的两条one,two 大于1数据不取出来)
2008 1 2 5 (剩下的一条one,two 大于1数据不取出来)
====================
帮你转到sql server区,会得到更多帮助
------解决方案--------------------
- SQL code
declare @main table( id int ,level int, rate int)insert into @main select 2007,1,20insert into @main select 2008,1,30declare @db table( id int ,one int, two int)insert into @db select 2007,1,3insert into @db select 2007,2,4insert into @db select 2007,5,1insert into @db select 2008,2,5insert into @db select 2007,4,5select m.id,m.level,b.one,b.twofrom @main mleft join @db b on m.id=b.idwhere b.one>1 and b.two>1/********************************id level one two----------- ----------- ----------- -----------2007 1 2 42008 1 2 52007 1 4 5********************************/