一个select的较难的问题。。。 在线等待。
我的表结构是:
id(系统自增标识)Eid(信息的id)Etype(信息类型)Econtent(信息内容)
1 wodidkdifdfi23 outcome sdfdsf@dfs.com
2 wodidkdifdfi23 income kjk@sdf.com
3 wodidkdifdfi23 message unknowns. sd.
4 dsfidsfdjfldi9 income di8lkfdoi@diof.com
5 dsfidsfdjfldi9 outcome iojhl@ef.com
由于Eid对应3种类型的信息,我现在做个界面想根据信息类型及信息内容来查询完整的条目:我在text1(outcome)中输入sdfdsf@dfs.com,并在text2(income)中输入kjk@sdf.com,我希望查出Eid为wodidkdifdfi23的3条记录。
也就是说,无论如何都要outcome,income或message一组显示。
要怎么办啊。。。
问题点数:100、回复次数:17Top
1 楼tangxiaosan001(阿三)回复于 2004-05-04 13:20:40 得分 0
告诉你思路。你可以通过outcome或者sdfdsf◎dfs.com等,先查询到eid(id)的信息
然后就用eid的信息来查询你要的信息。就是一个弯而已。Top
2 楼liaorui(更烦得很~ξ)回复于 2004-05-04 14:19:04 得分 0
楼上说的也是一个方法。Top
3 楼online(龙卷风V4.0--决战江湖(MS MVP-VB))回复于 2004-05-04 14:29:04 得分 100
select table1.eid,table1.etype,table1.econtent from table1,(select eid,etype,econtent from table1 where econtent='sdfdsf@dfs.com' ) a
,(select eid,etype,econtent from table1 where econtent='kjk@sdf.com') b
where table1.eid=a.eid and table1.eid=b.eidTop
4 楼kernel1_0(caniby)回复于 2004-05-04 15:17:33 得分 0
我也是像啊三说的 那样做的,可是那样的情况适应于只有一个条件。如果两个同时满足则很难处理。。你想一下啊。
再战江湖说的是自连接吗,我想这样是对的,可是我不太懂这个语法。可以说明下吗?当然我也会去查的。。。
还有谁有意见吗?Top
5 楼online(龙卷风V4.0--决战江湖(MS MVP-VB))回复于 2004-05-04 15:27:41 得分 0
如果你是sqlserver,放到查询分析器中执行,看看结果
a,b其实相当于两个表,与主表table关联,就可以取出来
Top
6 楼kernel1_0(caniby)回复于 2004-05-04 16:43:16 得分 0
多谢。。
我现在增加了起始时间和终止时间的查询条件。要如何做了。。原来我表里还有个datetime型的Edate字段。。
我很混乱呢。
我现在都是做的模糊查询呢,都在textn.text旁加了%,这次容易的写程序,如果模糊查询是由用户自己勾选复选筐定的,要如何实现,请说明下思路好吗???Top
7 楼online(龙卷风V4.0--决战江湖(MS MVP-VB))回复于 2004-05-04 16:53:13 得分 0
Private Sub Command3_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "select table1.eid,table1.etype,table1.econtent from table1,(select eid,etype,econtent from table1 where econtent='%" & text1.text & "%' ) a,(select eid,etype,econtent from table1 where econtent='%" & text2.text & "%') b Where table1.eid = a.eid And table1.eid = b.eid", mConn, 1, 3
MsgBox rs.RecordCount
End Sub
Top
8 楼online(龙卷风V4.0--决战江湖(MS MVP-VB))回复于 2004-05-04 16:53:56 得分 0
上面的有些问题
Private Sub Command3_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "select table1.eid,table1.etype,table1.econtent from table1,(select eid,etype,econtent from table1 where econtent like '%" & text1.text & "%' ) a,(select eid,etype,econtent from table1 where econtent like '%" & text2.text & "%') b Where table1.eid = a.eid And table1.eid = b.eid", mConn, 1, 3
MsgBox rs.RecordCount
End SubTop
9 楼kernel1_0(caniby)回复于 2004-05-04 17:16:09 得分 0
我的语句和你的一样。谢谢。
我想知道怎么把时间这个查询条件放进去啊。。
100分好像不够用了,你答了我这么多,花了你不少时间。我可以多给300分给你的。。
我是不是要做很多不同的情况啊。因为多个text的有填及没填等。。Top
10 楼online(龙卷风V4.0--决战江湖(MS MVP-VB))回复于 2004-05-04 17:38:14 得分 0
Private Sub Command3_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "select table1.eid,table1.etype,table1.econtent from table1,(select eid,etype,econtent from table1 where econtent like '%" & text1.text & "%' ) a,(select eid,etype,econtent from table1 where econtent like '%" & text2.text & "%') b Where table1.eid = a.eid And table1.eid = b.eid where edate>='"& text3.text &"' and edate<='" & text4.text & "'", mConn, 1, 3
MsgBox rs.RecordCount
End Sub
这段sql的我没有测试
//我是不是要做很多不同的情况啊。因为多个text的有填及没填等。。
是的
例如:if text1.text="" then
sql1
else
sql2
end ifTop
11 楼kernel1_0(caniby)回复于 2004-05-04 17:51:00 得分 0
多谢。。
那个where可能不行(在edate)前的。。
我的表里的edate字段是datetime型的,text取的是string,我可以直接像你那样比较两者的吗?
我老是觉得做if很烦:》Top
12 楼online(龙卷风V4.0--决战江湖(MS MVP-VB))回复于 2004-05-04 18:16:11 得分 0
rs.Open "select table1.eid,table1.etype,table1.econtent from table1,(select eid,etype,econtent from table1 where econtent like '%" & text1.text & "%' ) a,(select eid,etype,econtent from table1 where econtent like '%" & text2.text & "%') b Where table1.eid = a.eid And table1.eid = b.eid and edate>='"& text3.text &"' and edate<='" & text4.text & "'", mConn, 1, 3
修改了一下,可以用,通过测试
Top
13 楼tangxiaosan001(阿三)回复于 2004-05-04 19:50:34 得分 0
我觉得他的意思就是要查询到eid,然后就显示出来。
不过象他们那样连接,我没有深入研究过,我相信他们的很好。Top
14 楼tangxiaosan001(阿三)回复于 2004-05-04 19:57:58 得分 0
^_^,如果要满足多种条件那就and撒。Top
15 楼daisy8675(莫依 沉迷)回复于 2004-05-04 20:04:21 得分 0
怎麼寫這麼多查詢?
好玩, copy下Top
16 楼txlicenhe(马可)回复于 2004-05-04 20:16:05 得分 0
select * from 表 a
where exists
(select 1 from 表
where Eid = a.Eid
and (Econtent like '%sdfdsf@dfs.com%'
or Econtent like '%kjk@sdf.com%'
)
)
Top
17 楼kernel1_0(caniby)回复于 2004-05-04 21:42:55 得分 0
online(龙卷风V2.0--再战江湖) ,我再发个贴。给你100分啊。。Top




