oracle sql按列分组统计

mqkwyuun  于 2021-08-01  发布在  Java
关注(0)|答案(2)|浏览(358)

我在下面运行了一个查询,以获取我可以在输出中看到的数据计数,但它并没有按我所希望的那样工作
如何打印输出中列6和列7的计数?
我明白了吗?

  1. select col1, col2,
  2. col3, col4, decode(col5,'S','Success','F','Failed'), col6, col7, count(*)
  3. from mytable
  4. where col1 in (select FIELD1 from temp)
  5. and col8 = 4
  6. group by col1, col2, col3,col4,col5,col6,col7
nbewdwxp

nbewdwxp1#

看看这样行不行

  1. select count(col6), count(col7)
  2. from mytable
  3. where col1 in (select FIELD1 from temp)
  4. and col8 = 4;
yyyllmsg

yyyllmsg2#

你需要使用合适的 aggregate function 然后取下 col6 以及 col7GROUP BY 查询后的子句:

  1. select col1, col2, col3, col4, decode(col5,'S','Success','F','Failed'),
  2. count(col6), count(col7), count(*) -- used count for col6 and col7
  3. from mytable
  4. where col1 in (select FIELD1 from temp)
  5. and col8 = 4
  6. group by col1, col2, col3,col4,col5 -- removed col6 and col7 from here

相关问题