
如何根据查询的值 做为子查询的条件
如题,我的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,本来没有,这里写多了 展开
我的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,本来没有,这里写多了 展开
2个回答
展开全部
能把表截个图放这里哇
直观点好解决问题。
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
你问题没说清楚
直观点好解决问题。
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
你问题没说清楚
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询