如何提高数据库查询访问速度?

hqsee 2003-10-15 02:16:55
在SQL SERVER中,应客户要求做一些复杂的报表,用视图作为查询。往往最终的视图里嵌套了好多视图,有的视图甚至长至一两页。这样导致记录稍微一多,查询速度就很慢。请问高手如何解决此问题。
...全文
28 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hqsee 2003-10-16
  • 打赏
  • 举报
回复
把Person1,person2,person3需要合成一个字段。就是地区,人名。然后以地区,人名来统计。某个地区人名不能重复。
yoki 2003-10-15
  • 打赏
  • 举报
回复
你的person1,person2,person3我不知道有什么用处
yoki 2003-10-15
  • 打赏
  • 举报
回复
select AreaName,Person1,
Sum(
case BoxStuff when 1 then 1.5*TotalArea
case BoxStuff when 2 then 1.5*TotalArea
case BoxStuff when 3 then 1.5*TotalArea
case BoxStuff when 6 then 1.5*TotalArea
case BoxStuff when 7 then 1.5*TotalArea
case BoxStuff when 8 then 1.5*TotalArea
case BoxStuff when 9 then 2*TotalArea
else TotalArea
)
from table1
where date between '2002-01-01' and '2002-01-23'
group by AreaName,Perspon1
hqsee 2003-10-15
  • 打赏
  • 举报
回复
参数只有两个,就是起始日期。需要查询不同区域名称,不同人的TotalArea之和。(即查询出一组数据,这些数据有不用的AreaName,Person名称。)需要用Group By.但Person字段有三个。另外是Len(Replace(BoxStuff,'-','')而不是你写的。
golden24kcn 2003-10-15
  • 打赏
  • 举报
回复

不大明白你的意思 第一个问题有什么可说的吗? select sum(table1.TotaArea) where
date between 'xxxx-xx-xx' and 'xxxx-xx-xx' and person='xxxx'
第二个问题更晕,一点也不理解你的意思了,只是猜一下
select newtotalarea = case len(totalarea) where 1 then totalarea * 2 when 3 then totalarea * 5 end from talbe1 where .....
hqsee 2003-10-15
  • 打赏
  • 举报
回复
比如一表中有字段Date,AreaName,BoxStuff,Person1,Person2,Person3,TotalArea
欲查询某段时间内某个AreaName,某个Person的TotalArea之和。另外要根据BoxStuff的内容来算TotalArea.(根据BoxStuff中字母的个数来算TotalArea,比如A-A-B表示有三层。"-"不算。如果有1,2,3层TotalArea*1.5.4,5层不变。6,7,8层则TotalArea*1.5 .9层的话则是TotalArea*2.最多有9层。),请问如何写这样的视图。
golden24kcn 2003-10-15
  • 打赏
  • 举报
回复
从程序角度的优化你自己最清楚,我的建议就是少一些子查询,多一些连接查询,少用聚合函数.从程序配置角度,客户端强烈要求删除了NETBIOS协议,速度就会快15%以上

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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