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

请详细解释 下面的 sql 语句解决办法

2012-01-23 
请详细解释 下面的 sql 语句select count(*) as iterance_count from(SELECT DBVIEW_artru_ZD.ARTRUID, DB

请详细解释 下面的 sql 语句
select count(*) as iterance_count from(SELECT DBVIEW_artru_ZD.ARTRUID, DBVIEW_artru_ZD.CompanyCode, DBVIEW_artru_ZD.PublishDate, DBVIEW_artru_ZD.ARTRUStyle, DBVIEW_artru_ZD.ARTRUItem, DBVIEW_artru_ZD.Currency, DBVIEW_artru_ZD.ARTRU1, DBVIEW_artru_ZD.ARTRU2, DBVIEW_artru_ZD.ARTRU3, DBVIEW_artru_ZD.ARTRU4, DBVIEW_artru_ZD.ARTRU5, DBVIEW_artru_ZD.ARTRU6, DBVIEW_artru_ZD.ARTRU7, DBVIEW_artru_ZD.ARTRU8, DBVIEW_artru_ZD.ARTRU9, DBVIEW_artru_ZD.ARTRU10, DBVIEW_artru_ZD.ARTRU11, DBVIEW_artru_ZD.ARTRU12, DBVIEW_artru_ZD.ARTRU13, DBVIEW_artru_ZD.ARTRU14, DBVIEW_artru_ZD.ARTRU15, DBVIEW_artru_ZD.ARTRU16, DBVIEW_artru_ZD.ARTRU17, DBVIEW_artru_ZD.ARTRU18, DBVIEW_artru_ZD.ARTRU19, DBVIEW_artru_ZD.ARTRU20, DBVIEW_artru_ZD.ARTRU21, DBVIEW_artru_ZD.ARTRU22, DBVIEW_artru_ZD.ARTRU23, DBVIEW_artru_ZD.ARTRU24, DBVIEW_artru_ZD.ARTRU25, DBVIEW_artru_ZD.ARTRU26, DBVIEW_artru_ZD.ARTRU27, DBVIEW_artru_ZD.ARTRU28, DBVIEW_artru_ZD.ARTRU29, DBVIEW_artru_ZD.ARTRU30, DBVIEW_artru_ZD.ARTRU31,DBVIEW_artru_ZD.GUID AS _GUID_DBVIEW_artru_ZD FROM DBVIEW_artru_ZD DBVIEW_artru_ZD )YM group by ARTRUID having count(*)>1

[解决办法]

SQL code
select count(*) as iterance_count from(    SELECT         DBVIEW_artru_ZD.ARTRUID, DBVIEW_artru_ZD.CompanyCode, DBVIEW_artru_ZD.PublishDate, DBVIEW_artru_ZD.ARTRUStyle,         DBVIEW_artru_ZD.ARTRUItem, DBVIEW_artru_ZD.Currency, DBVIEW_artru_ZD.ARTRU1, DBVIEW_artru_ZD.ARTRU2, DBVIEW_artru_ZD.ARTRU3,         DBVIEW_artru_ZD.ARTRU4, DBVIEW_artru_ZD.ARTRU5, DBVIEW_artru_ZD.ARTRU6, DBVIEW_artru_ZD.ARTRU7, DBVIEW_artru_ZD.ARTRU8,         DBVIEW_artru_ZD.ARTRU9, DBVIEW_artru_ZD.ARTRU10, DBVIEW_artru_ZD.ARTRU11, DBVIEW_artru_ZD.ARTRU12,         DBVIEW_artru_ZD.ARTRU13, DBVIEW_artru_ZD.ARTRU14, DBVIEW_artru_ZD.ARTRU15, DBVIEW_artru_ZD.ARTRU16,         DBVIEW_artru_ZD.ARTRU17, DBVIEW_artru_ZD.ARTRU18, DBVIEW_artru_ZD.ARTRU19, DBVIEW_artru_ZD.ARTRU20,         DBVIEW_artru_ZD.ARTRU21, DBVIEW_artru_ZD.ARTRU22, DBVIEW_artru_ZD.ARTRU23, DBVIEW_artru_ZD.ARTRU24,         DBVIEW_artru_ZD.ARTRU25, DBVIEW_artru_ZD.ARTRU26, DBVIEW_artru_ZD.ARTRU27, DBVIEW_artru_ZD.ARTRU28,         DBVIEW_artru_ZD.ARTRU29, DBVIEW_artru_ZD.ARTRU30, DBVIEW_artru_ZD.ARTRU31,DBVIEW_artru_ZD.GUID AS _GUID_DBVIEW_artru_ZD     FROM DBVIEW_artru_ZD DBVIEW_artru_ZD )YM --独立子查询,从这个表中group by ARTRUID having count(*)>1 --根据ARTRUID分组,取出分组后count(1)> 1 的集合
[解决办法]
SQL code
--一个统计查询语句,统计记录数:select count(*) as iterance_count from(--从一个子查询来统计SELECT DBVIEW_artru_ZD.ARTRUID, DBVIEW_artru_ZD.CompanyCode, DBVIEW_artru_ZD.PublishDate, DBVIEW_artru_ZD.ARTRUStyle, DBVIEW_artru_ZD.ARTRUItem, DBVIEW_artru_ZD.Currency, DBVIEW_artru_ZD.ARTRU1, DBVIEW_artru_ZD.ARTRU2, DBVIEW_artru_ZD.ARTRU3, DBVIEW_artru_ZD.ARTRU4, DBVIEW_artru_ZD.ARTRU5, DBVIEW_artru_ZD.ARTRU6, DBVIEW_artru_ZD.ARTRU7, DBVIEW_artru_ZD.ARTRU8, DBVIEW_artru_ZD.ARTRU9, DBVIEW_artru_ZD.ARTRU10, DBVIEW_artru_ZD.ARTRU11, DBVIEW_artru_ZD.ARTRU12, DBVIEW_artru_ZD.ARTRU13, DBVIEW_artru_ZD.ARTRU14, DBVIEW_artru_ZD.ARTRU15, DBVIEW_artru_ZD.ARTRU16, DBVIEW_artru_ZD.ARTRU17, DBVIEW_artru_ZD.ARTRU18, DBVIEW_artru_ZD.ARTRU19, DBVIEW_artru_ZD.ARTRU20, DBVIEW_artru_ZD.ARTRU21, DBVIEW_artru_ZD.ARTRU22, DBVIEW_artru_ZD.ARTRU23, DBVIEW_artru_ZD.ARTRU24, DBVIEW_artru_ZD.ARTRU25, DBVIEW_artru_ZD.ARTRU26, DBVIEW_artru_ZD.ARTRU27, DBVIEW_artru_ZD.ARTRU28, DBVIEW_artru_ZD.ARTRU29, DBVIEW_artru_ZD.ARTRU30, DBVIEW_artru_ZD.ARTRU31,DBVIEW_artru_ZD.GUID AS _GUID_DBVIEW_artru_ZD FROM DBVIEW_artru_ZD DBVIEW_artru_ZD --上面一个子查询,用了一大堆另外,其实,由于只是从一个表中查的,完全可以把除 from 后面的那个 DBVIEW_artru_ZD 保留外,--其他DBVIEW_artru_ZD及其后面的.号全去除.即,它等价于:/*SELECT ARTRUID, CompanyCode, PublishDate, ARTRUStyle, ARTRUItem, Currency, ARTRU1, ARTRU2, ARTRU3, ARTRU4, ARTRU5, ARTRU6, ARTRU7, ARTRU8, ARTRU9, ARTRU10, ARTRU11, ARTRU12, ARTRU13, ARTRU14, ARTRU15, ARTRU16, ARTRU17, ARTRU18, ARTRU19, ARTRU20, ARTRU21, ARTRU22, ARTRU23, ARTRU24, ARTRU25, ARTRU26, ARTRU27, ARTRU28, ARTRU29, ARTRU30, ARTRU31,GUID AS _GUID_DBVIEW_artru_ZD FROM DBVIEW_artru_ZD*/)YM group by ARTRUID having count(*)>1--以artruid分组进行统计,列出行数大于1的artruid,而且,在select 子句中,artruid竟然未列出,那统计出来的一堆数据,是没有意义的,不知道哪个count是属于哪个artruid--由于统计分组只有一列,因此上面的子查询可以只用一列,即上面的全部语句等价于:select artruid,count(*) as iterance_count from dbview_artru_zd group by artruid having count(*)>1--怀疑这是由机器自动生成的查询语句,人脑不会如此低劣. 


[解决办法]

探讨
SQL code

--一个统计查询语句,统计记录数:
select count(*) as iterance_count from(
--从一个子查询来统计
SELECT DBVIEW_artru_ZD.ARTRUID, DBVIEW_artru_ZD.CompanyCode, DBVIEW_artru_ZD.PublishDate, DBVIEW_artru_ZD.ARTRUStyl……

热点排行