关于select 的一条sql语句怎么写?

来源:百度知道 编辑:UC知道 时间:2024/06/12 14:19:39
表A
DWBH dwys
123 asd
342 ass
454 ere
878 SEA
999 SDWW

表B
DWBH BZ XJZT SDAS
123 #SDA 01 O90D
342 #234 01 87SS
454 #567 02 SA44
878 #SDA 01 ASS3

通过DWBH这个字段,根据表B中条件为(XJZT=01 and BZ=#SDA)的DWBH数据,查出表A中dwys的值。
这个sql我想了半天,没有找出办法。
多谢大家帮忙!!

或者用分开语句,那就要写循环了:
set rsy=server.createobject("adodb.recordset")
sql = "select DWBH from 表B where XJZT=01 and BZ=#SDA"
rsy.open sql,conn,1,1
set rs=server.createobject("adodb.recordset")
sql1 = "select DWBH from 表A where DWBH="&rsy("DWBH")
rs.open sql1,conn,1,1
Response.Write rs("dwys")

select a.dwys from 表A a,表B b where a.dwbh=b.dwbh and b.xjzt='01' and b.bz='#sda'

select dwys from A where DWBH in (select DWBH from B where XJZT=01 and BZ=#SDA)

赞成zs198910208818,但根据数据类型格式不同

select days
from a表
where a.DWBH in (
select DWBH
from b表
where XJZT=01 and BZ=#SDA
)
最好

select dwys from A where DWBH in (select DWBH from B where XJZT=01 and BZ='#SDA')