国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

mysql - sql 統計某列下的4個值,分別是多少個

瀏覽:101日期:2022-06-19 08:34:54

問題描述

mysql - sql 統計某列下的4個值,分別是多少個

dg_order_time下的4個值 1,2,3,4他們各自的總和是多少個?是各自,不是這列的總和...

問題解答

回答1:

你是要實現每一行數據中的所有相同數的總和嗎?所有行的1的總和;所有行2的總和...。是不!

回答2:

這是橫的

select a.t1, b.t2, c.t3, d.t4from (select count(*) t1 from table where col like ’%1%’) a,(select count(*) t2 from table where col like ’%2%’) b,(select count(*) t3 from table where col like ’%3%’) c,(select count(*) t4 from table where col like ’%4%’) d

這是豎的

select ’t1’, count(*) from table where col like ’%1%’union allselect ’t2’, count(*) from table where col like ’%2%’union allselect ’t3’, count(*) from table where col like ’%3%’union allselect ’t4’, count(*) from table where col like ’%4%’

大致思路就是這樣

回答3:

select nvl(substr(t.str, 0, 1),0) + nvl(substr(t.str, (case when instr(t.str, ’,’, 1, 1) < 0 then -1 when instr(t.str, ’,’, 1, 1) > 0 then instr(t.str, ’,’, 1, 1)+1 end), 1),0) + nvl(substr(t.str, (case when instr(t.str, ’,’, 1, 2) < 0 then -1 when instr(t.str, ’,’, 1, 2) > 0 then instr(t.str, ’,’, 1, 2)+1 end), 1),0) + nvl(substr(t.str, (case when instr(t.str, ’,’, 1, 3) < 0 then -1 when instr(t.str, ’,’, 1, 3) > 0 then instr(t.str, ’,’, 1, 3)+1 end), 1),0) from test_calc t;

mysql - sql 統計某列下的4個值,分別是多少個

mysql - sql 統計某列下的4個值,分別是多少個

主站蜘蛛池模板: 龙南县| 邢台县| 柘城县| 奇台县| 湟源县| 肇州县| 永德县| 利川市| 宁津县| 雷州市| 梅州市| 桐城市| 临漳县| 改则县| 舟山市| 黄浦区| 科尔| 柳江县| 陇南市| 全南县| 中西区| 崇信县| 玉田县| 宜都市| 安多县| 贡觉县| 临桂县| 武义县| 彝良县| 额敏县| 忻州市| 福清市| 大安市| 晋州市| 怀来县| 百色市| 承德县| 张家港市| 南通市| 额济纳旗| 永寿县|