0

count(*)複数の範囲の合計を取得したいと思います。

たとえばselect count(*)、ある場所の範囲から別の場所へのステートメントが 10 個あります。

10 の位置範囲すべての合計を取得したいと思います。

SELECT count (*) 
FROM locn_hdr 
WHERE locn_brcd 
BETWEEN 'B2121' AND 'B2144'

SELECT count (*) 
FROM locn_hdr 
WHERE locn_brcd 
BETWEEN 'B2201' AND 'B2224' 
4

2 に答える 2

0

mysql で次のクエリを試してください。

(sum(if('B2121' と 'B2144' の間の locn_brcd,1,0))+sum(if('B2201' と 'B2224' の間の locn_brcd,1,0))) を locn_hdr からの合計として選択します

于 2013-08-09T14:34:58.660 に答える
0

個々の結果が必要な場合は、次のクエリを使用できます。

select sum(if(locn_brcd between 'B2121' and 'B2144',1,0)) as ca1, 
    sum(if(locn_brcd between 'B2201' and 'B2224',1,0)) as ca2,
    sum(if(locn_brcd between 'B2322' and 'B2344',1,0)) as ca3,
    sum(if(locn_brcd between 'B2401' and 'B2424',1,0)) as ca4,
    sum(if(locn_brcd between 'B2521' and 'B2544',1,0)) as ca5,
    sum(if(locn_brcd between 'B2601' and 'B2624',1,0)) as ca6,
    sum(if(locn_brcd between 'B0317' and 'B0340',1,0)) as ca7,
    sum(if(locn_brcd between 'B0401' and 'B0424',1,0)) as ca8,
    sum(if(locn_brcd between 'B0517' and 'B0540',1,0)) as ca9,
    sum(if(locn_brcd between 'B0601' and 'B0624',1,0)) as ca10
from locn_hd;
于 2013-08-15T07:41:24.600 に答える