一个复杂SQL 语句问题(300)

  • 主题发起人 主题发起人 mzr
  • 开始时间 开始时间
如果按上述表结构和记录,把查询View_Sumwmresult和view_Wmresult改为Table表,下面这条SELECT a.DY, a.PH, a.KH, a.KX, (SELECT COUNT(b.dz) AS Zh1 FROM table2 b WHERE (a.kh = b.kh) AND (b.dz < 50) AND (b.dh <> "fk")) AS Zh1, (SELECT COUNT(b.dz) AS Zh1 FROM table2 b WHERE (a.kh = b.kh) AND (b.dz >= 50)and(b.dz<100) AND (b.dh <> "fk")) AS Zh2FROM table1 AS aWHERE (a.DY='01')ORDER BY a.DY, a.PH, a.KX, a.KH;不会报错,得到的结果也是正确。可为什么查询通不过呢
 
各位有没有更优化的SQL语句也可以在些贴出来[:D]
 
用这个吧,也是受你的启发。可能是因为你的视图中已经用了A和B原因吧。SELECT TOP 100 PERCENT z.DY, z.PH, z.KH, z.KX, (SELECT COUNT(dz) AS Zh1 FROM View_WmResult y WHERE (z.kh = y.kh) AND (dz < 50) AND (dh <> 'fk')) AS Zh1, (SELECT COUNT(dz) AS Zh2 FROM View_WmResult y WHERE (z.kh = y.kh) AND (dz >= 50) AND (dz < 100) AND (dh <> 'fk')) AS Zh2FROM VIEW_SumWmresult AS zWHERE (z.DY='01')ORDER BY z.DY, z.PH, z.KX, z.KH
 
还是有点麻烦的。一个人还真想不到。
 
hctdnjy厉害啊~~
 
谢谢。学习中
 
谢谢hctdnjy啊,ACCESS太弱智了,哈哈
 
散分了,谢谢各位的指点
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
843
import
I
I
回复
0
查看
687
import
I
S
回复
0
查看
928
SUNSTONE的Delphi笔记
S
后退
顶部