sql:如何对特定列使用count,(或)按字段名称对特定列进行计数

时间:2012-11-02 04:51:52

标签: sql

在我的查询中,我需要按字段名称

来计算特定列
SELECT 
  C.INC_COUNT, MIN_X, MIN_Y, MAX_X, MAX_Y, B.STATE_ABBR,
  B.STATE_NAME, B.LATITUDE, B.LONGITUDE, A.STATE, GEO_ID, 
  concat(A.LSAD_TRANS,' ' , A.NAME) DIST_NAME, 
  A.LSAD, GeometryType(SHAPE) GEO_TYPE, AsText(SHAPE) GEOM  
from SHAPE_LAYERS A 
join SHAPE_LAYER_STATE_DESC B 
  on ( A.state = B.state) 
left outer join INC_DIST_SUMMARY_ALL C 
  on (C.SHAPE_GEO_ID = A. GEO_ID)

这里我必须按

计算
 B.STATE_NAME ,C.INC_COUNT

如果字段名称为nevada,则表示我必须获取所有neveda value count和C.INC_COUNT。

1 个答案:

答案 0 :(得分:1)

试试这个

  SELECT count(C.INC_COUNT), MIN_X, MIN_Y, MAX_X, MAX_Y,
  B.STATE_ABBR, count(B.STATE_NAME),B.LATITUDE,B.LONGITUDE,
  A.STATE, GEO_ID, concat(A.LSAD_TRANS,' ' , A.NAME) DIST_NAME,
  A.LSAD, GeometryType(SHAPE) GEO_TYPE, AsText(SHAPE) GEOM  
  from SHAPE_LAYERS A join SHAPE_LAYER_STATE_DESC B
  on ( A.state = B.state) 
  left outer join INC_DIST_SUMMARY_ALL C
  on (C.SHAPE_GEO_ID = A. GEO_ID)