首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql-两个查询

2013-08-09 
sql---两个查询1.SELECT D.WGMC, D.JDMC, D.HS, COUNT(6) ZSFROM(SELECT C.WGMC WGMC,C.WGBM WGBM,C.JDMC

sql---两个查询
1.

SELECT D.WGMC, D.JDMC, D.HS, COUNT(6) ZSFROM(SELECT C.WGMC WGMC,C.WGBM WGBM,C.JDMC JDMC,C.HS HSFROM (SELECT COUNT(2) HS,WG.WGMC,WG.WGBM,JD.JDMC FROM T_SHSJGL_GH H, T_SHSJGL_WG WG,T_SHSJGL_SQ SQ,T_SHSJGL_JD JD WHERE H.GRID_ID = WG.ID  AND WG.SQID = SQ.ID AND SQ.JDID = JD.ID  GROUP BY WG.WGMC,WG.WGBM,JD.JDMC ) C WHERE C.HS<70) D,T_SHSJGL_GZ GZWHERE GZ.SZWG=D.WGBMGROUP BY D.WGMC, D.JDMC, D.HSORDER BY D.HS ASC



2.
SELECT C.WGMC WGMC,C.JDMC JDMC,C.HS HS,COUNT(C.ZBM) ZSFROM (SELECT COUNT(2) HS,WG.WGMC WGMC,GZ.ZBM ZBM,JD.JDMC  JDMCFROM T_SHSJGL_GH H, T_SHSJGL_GZ GZ,T_SHSJGL_WG WG,T_SHSJGL_SQ SQ,T_SHSJGL_JD JDWHERE H.GRID_ID = WG.ID AND GZ.SZWG=WG.WGBM AND WG.SQID = SQ.ID AND SQ.JDID = JD.ID  GROUP BY WG.WGMC,GZ.ZBM,JD.JDMC ) C WHERE C.HS<70GROUP BY C.WGMC,C.JDMC,C.HSORDER BY C.HS ASC


两者功能相同,但是第一个比第二个查询的快很多,具体应该是提前C.HS<70筛选了,然后后面的比较就是在筛选后的结果集里面提取了,所以快吧...以后sql语句如果有条件筛选,就先筛选。

热点排行