sql server一个查询语句问题~~急~~求高手帮帮忙~在线等~

Ternence 2012-02-10 01:54:00

select top 4 Books_Cid,sum(Books_volume)
as salink from Books t where (select *from Indent where Indent_State='0' and Indent_Time between '2012-02-1 00:00:00' and '2012-02-31 00:00:00')
Books_Cid like '102%' group by Books_Cid order by salink desc



select *from Indent where Indent_State='0' and Indent_Time between '2012-02-1 00:00:00' and '2012-02-31 00:00:00'

这句是我的需求句子。 也就是说 在这句的位置 加一个类似这样的一个查询语句。
ps 需求:在我查询books 时,先查询 indent表里面的条件语句 然后在查询indent表里的数据结果里 在到books表里查询剩下的语句。
大虾们帮帮忙 感激不尽 -在线等~
...全文
98 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ternence 2012-02-10
  • 打赏
  • 举报
回复
7楼 老猫
10楼 紫竹
正解 非常感谢 ~~

也谢谢9楼bestjfliu ~和大家的帮忙~~
zhouzhijian888 2012-02-10
  • 打赏
  • 举报
回复
复杂!~~~~~~~~~等待高手!~~
紫竹林畔 2012-02-10
  • 打赏
  • 举报
回复
--try

select top 4 Books_Cid,
sum(Books_volume)as salink
from Books t
where exists(select 1
from Indent
where Indent_State='0' and Indent_Time between '2012-02-1 00:00:00' and '2012-02-31 00:00:00'
and Indent_Bid=t.Books_id)
and
Books_Cid like '102%' group by Books_Cid order by salink desc
bestjfliu 2012-02-10
  • 打赏
  • 举报
回复
select 字段名 from 表中 where 条件
条件格式key = value这样的键值对应。

而你的条件中有一个却没有键值对应。 从上面也没看出来你想使用哪一个字段来过滤数据。
老猫五号 2012-02-10
  • 打赏
  • 举报
回复
select top 4 Books_Cid,sum(Books_volume) as salink
from Books t
where t.Books_id in (
select Indent_Bid
from Indent
where Indent_State='0' and
Indent_Time between '2012-02-1 00:00:00' and '2012-02-31 00:00:00'
) and Books_Cid like '102%'
group by Books_Cid
order by salink desc

老猫五号 2012-02-10
  • 打赏
  • 举报
回复
select top 4 Books_Cid,sum(Books_volume) as salink
from Books t
where t.Books_id in (
select Indent_Bid
from Indent
where Indent_State='0' and
Indent_Time between '2012-02-1 00:00:00' and '2012-02-31 00:00:00'
) and Books_Cid like '102%'
group by Books_Cid
order by salink desc

Ternence 2012-02-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lhqdyy9 的回复:]

select top 4 Books_Cid,sum(Books_volume)
as salink from Books t where (select *from Indent where Indent_State='0' and Indent_Time between '2012-02-1 00:00:00' and '2012-02-31 00:00:00')
Books_……
[/Quote]

Indent 表里的 Indent_Bid 为 books表的 Books_id
紫竹林畔 2012-02-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 alikeyount 的回复:]
引用 1 楼 的回复:

听不懂你的描述


所有条件:通过时间范围在indent表里查询数据,得到的数据 ,然后在books表里查询字段为Books_volume的信息(信息为数字)。倒序排序Books_volume的信息并且Books_Cid不相同的前4条信息(如果Books_Cid相同,相同数据的Books_volume信息就相加)。
[/Quote]
还没说到重点
两个表靠什么做关联条件
Ternence 2012-02-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

听不懂你的描述
[/Quote]

所有条件:通过时间范围在indent表里查询数据,得到的数据 ,然后在books表里查询字段为Books_volume的信息(信息为数字)。倒序排序Books_volume的信息并且Books_Cid不相同的前4条信息(如果Books_Cid相同,相同数据的Books_volume信息就相加)。
老猫五号 2012-02-10
  • 打赏
  • 举报
回复
select top 4 Books_Cid,sum(Books_volume)
as salink from Books t where (select *from Indent where Indent_State='0' and Indent_Time between '2012-02-1 00:00:00' and '2012-02-31 00:00:00')
Books_Cid like '102%' group by Books_Cid order by salink desc

你的Books表和Indent有什么关联条件?
比如:
select top 4 Books_Cid,sum(Books_volume) as salink
from Books t
where t.Id in (
select Id
from Indent
where Indent_State='0' and
Indent_Time between '2012-02-1 00:00:00' and '2012-02-31 00:00:00'
) and Books_Cid like '102%'
group by Books_Cid
order by salink desc



--小F-- 2012-02-10
  • 打赏
  • 举报
回复
在我查询books 时,先查询 indent表里面的条件语句 然后在查询indent表里的数据结果里 在到books表里查询剩下的语句。


麻烦再翻一下 没懂
紫竹林畔 2012-02-10
  • 打赏
  • 举报
回复
听不懂你的描述

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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