当前位置: 代码迷 >> Sql Server >> select distinct 列名,count(*) from 表名 group by 列名 的结果怎么导入另一个表中
  详细解决方案

select distinct 列名,count(*) from 表名 group by 列名 的结果怎么导入另一个表中

热度:492   发布时间:2016-04-24 09:41:25.0
select distinct 列名,count(*) from 表名 group by 列名 的结果如何导入另一个表中
我写了以下的语句来统计表中相关列的数量:

select distinct quyu,sheng,hangyie,qte_bjmc,qte_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,qte_bjmc,qte_mc
select distinct quyu,sheng,hangyie,qtf_bjmc,qtf_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,qtf_bjmc,qtf_mc
select distinct quyu,sheng,hangyie,ckj_gys,ckj_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,ckj_gys,ckj_mc 


现在想将统计的结果加入到一个新表中再做分析.  该如何编写程序
------解决思路----------------------
引用:
完整的语句如下, 

SELECT * INTO NT1119 FROM  (
 select distinct quyu,sheng,hangyie,qta_bjmc,qta_mc ,count(*) [COUNT] from biyan002 group by quyu,sheng,hangyie,qta_bjmc,qta_mc
 UNION
select distinct quyu,sheng,hangyie,qtb_bjmc,qtb_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,qtb_bjmc,qtb_mc
 UNION
select distinct quyu,sheng,hangyie,qtc_bjmc,qtc_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,qtc_bjmc,qtc_mc
 UNION
select distinct quyu,sheng,hangyie,qtd_bjmc,qtd_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,qtd_bjmc,qtd_mc
 UNION
select distinct quyu,sheng,hangyie,qte_bjmc,qte_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,qte_bjmc,qte_mc
 UNION
select distinct quyu,sheng,hangyie,qtf_bjmc,qtf_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,qtf_bjmc,qtf_mc
 UNION
select distinct quyu,sheng,hangyie,ckj_gys,ckj_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,ckj_gys,ckj_mc 
 UNION
select distinct quyu,sheng,hangyie,t301a_gys,t301a_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,t301a_gys,t301a_mc
 UNION 
select distinct quyu,sheng,hangyie,zydy_gys,zydy_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,zydy_gys,zydy_mc
 UNION
select distinct quyu,sheng,hangyie,pc_dy_gys,pc_dy_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,pc_dy_gys,pc_dy_mc
 UNION
select distinct quyu,sheng,hangyie,nc_gys,nc_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,nc_gys,nc_mc
 UNION
select distinct quyu,sheng,hangyie,yp_gys,yp_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,yp_gys,yp_mc
 UNION
select distinct quyu,sheng,hangyie,zb_gys,zb_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,zb_gys,zb_mc
 UNION
select distinct quyu,sheng,hangyie,cpu_gys,cpu_mc ,count(*) from biyan002 group by quyu,sheng,hangyie,cpu_gys,cpu_mc)


执行后,得到的提示如下:
消息 102,级别 15,状态 1,第 28 行
')' 附近有语法错误。


不太明白,( )是一对一了,哪里的语法错了?
最后面加个表别名
  相关解决方案