注册 登录
编程论坛 SQL Server论坛

遇到一个多变查询的问题,纠结啊,在线求助。

liangfengfen 发布于 2011-06-02 20:15, 732 次点击
根据条件查询到一个景点A,并查询出该景点相关的所有的片B。
A.id=B.sid


用一个查询语句写出来,看了好久都不会啊。求助高手帮忙啦。谢谢
4 回复
#2
go20112011-06-02 22:32
看不懂你的题目,能不能多给点信息
#3
liangfengfen2011-06-03 09:42
create proc pro_PAS_ShowCaseInfoList
@tid int,
@pageindex int,
@pagesize int
as
  select top(@pagesize) * from PAS_ShowCaseInfo   
      where isshow=1 and tid=@tid and id not in (select top ((@pageindex-1)*@pagesize) id from PAS_ShowCaseInfo
                                                       where isshow =1 and tid=@tid order by publishtime desc ,id desc)
             order by publishtime desc,id desc
go
------------------------------
select count(id) from PAS_ShowCasePhotos where sid in (select id from PAS_ShowCaseInfo where tid=@tid) group by sid

就是把横线下面的sql语句加到上面的存储过程里,写成一个查询语句。怎么,搞啊。谢谢了
#4
panyanpan2011-06-03 10:02
没大 明白你的意思
你直接 把 这句
select count(id) from PAS_ShowCasePhotos where sid in (select id from PAS_ShowCaseInfo where tid=@tid) group by sid
放进 存储过程不行吗?
#5
tw9202172011-06-03 11:54
這種多表查詢一般都是寫存儲過程啦.

SELECT A1,A2,A3 FROM A WHERE ....
UNION
SELECT A1,A2,B3 AS A3 FROM B WHERE ...

應該能解決你的問題

你的意思應該是根據表A給的條件(前提是表A那個條件和表B的一個字段相對應)查詢出表B中的值
1