如何根据查询的值 做为子查询的条件

如题,我的SQL语句:selecttop50id,title,(selectcount(*)idfrommarkwherenewsid=id)asrem,sdate,or... 如题,
我的SQL语句:
select top 50 id,title,(select count(*) id from mark where newsid=id) as rem,sdate,ordernum from news order by sdate desc
这句中的ID newsid=id 我想用外面查询的ID值,但是弄不起,

想实现的总体意思是,按时间排序显示字段和另一表中ID值等于当前查询的ID值的记录总数,

如果在程序里循环是没问题,但是根据需求,要一个查询里显示出来.
我是在我的网站,:www.wotui.net中要用的,
count(*) Id 这多了一个,ID,本来没有,这里写多了
展开
 我来答
垂头大魔王
2009-11-26 · TA获得超过127个赞
知道答主
回答量:130
采纳率:0%
帮助的人:32.4万
展开全部
能把表截个图放这里哇
直观点好解决问题。
select top 50 id,title,(select count(*) from mark where newsid=(select id from 另外哪一张表)) as rem,sdate,ordernum from news order by sdate desc

还有,(select count(*) from mark where newsid=(select id from 另外哪一张表)) 你给它的定义是什么。。是newsid 还是别的
select top 50 id,title,newsid=(select count(*) from mark where newsid=(select id from 另外哪一张表)) as rem,sdate,ordernum from news order by sdate desc
你问题没说清楚
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
titian2046
2009-11-26 · 超过12用户采纳过TA的回答
知道答主
回答量:26
采纳率:0%
帮助的人:0
展开全部
select top 50 id,title,(select count(*) from mark where mark.newsid=news.id) as rem,sdate,ordernum from news order by sdate desc
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式