求sql语句,答案正确立即给分

cxiaobao 2002-10-14 05:29:12
有三个表,结构如下:
表1: customize_info:
(
id number(10) not null,

//这个publish_id与publish_info中的id对应
publish_id number(10) not null,

//这个user_id 与 user中的id对应
user_id number(10) not null,

status varchar2(1)
)

表2: publish_info:
(
id number(10) not null,

//这个user_id 与 user中的id对应
user_id number(10) not null,

msg varchar2(1024) not null
)

表3: user
(
id number(10) not null,
phone varchar2(20) not null
)


我现在想做的操作是这样的。
1:从表customize_info中取出status是null的记录
select id, publish_id, user_id userid1 from customzie_info where status is null

2:遍历上面的结果,对每一条记录做如下操作:
select phone from user where id = (value of userid1)

select user_id userid2,msg from publish_info where id = publish_id

select phone from user where id = (value of userid2)

我的问题是能不能查询一次数据库就把我所要的东西查出来呢?
我使用下面的语句:
select a.msg content ,b.phone fromphone, c.id infoid, d.phone tophone
from publish_info a ,user b ,customize_info c ,user d
where a.user_id = b.id
and a.id =c.publish_id
and d.id = c.user_id
and c.status is null

但结果是错的。(好象叉乘了)

正确的sql语句该怎么写?(或者不可能?)
...全文
27 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxiaobao 2002-10-14
  • 打赏
  • 举报
回复
非常感谢谢各位老大的热心帮助,问题解决了!这个帖子在数据库版还有一份:请各位去拿分。
http://www.csdn.net/expert/topic/1095/1095721.xml?temp=.3346979
huxiaobo 2002-10-14
  • 打赏
  • 举报
回复
试一下:SELECT a.id, a.publish_id, a.user_id a.userid1 b.phone c.user_id c.userid2,c.msg
from customzie_info a ,user b ,publish_info c,
where (status is null)
AND a.id in (select userid1 from user)
AND a.publish_id in (select publish_id from publish_info)
AND a.id in (select userid2 from user)
qybao 2002-10-14
  • 打赏
  • 举报
回复
试试
select ta.fromphone,tb.msg,tb.tophone
from (select A.phone as fromphone,B.publish_id as pid from [user] A,customzie_info B where B.status is not null and A.id=B.user_id) as ta,
(select C.msg as msg,C.publish_id as pid,D.phone as tophone from publish_info C,[user] D where C.user_id=D.id) as tb
where ta.pid=tb.pid
hydnoahark 2002-10-14
  • 打赏
  • 举报
回复
select A.id, A.publish_id, A.user_id as userid1
,B.phone
,C.user_id as userid2,C.msg
,D.phone
from customzie_info as A
inner join user as B
on A.user_id=B.id
inner join publish_info as C
on A.publish_id=C.id
inner join user as D
on C.user_id=D.id
where A.status is null
athere_08 2002-10-14
  • 打赏
  • 举报
回复
这样:select phone
from customzie_info ,user
where status is null
UNION
select phone
from customzie_info , publish_info,user
where customzie_info.status is null
and publish_info.publish_id=customzie_info.publish_id
and publish_info.user_id=user.id
没这样用过,不知可不可以。

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧