首页 > 开发 > 综合 > 正文

Multiple在表中的计算

2024-07-21 02:33:27
字体:
来源:转载
供稿:网友

  create table myTable (
  this Varchar2(10),
  that Varchar2(10)
  );
  
  insert into myTable values ('that'   , 'the other');
  insert into myTable values ('confusing', 'the other');
  insert into myTable values ('this'   , 'that'   );
  insert into myTable values ('this'   , 'that'   );
  insert into myTable values ('that'   , 'confusing');
  insert into myTable values ('confusing', 'that'   );
  insert into myTable values ('confusing', 'confusing');
  insert into myTable values ('that'   , 'the other');
  insert into myTable values ('this'   , 'that'   );
  insert into myTable values ('confusing', 'the other');
  
  select
  count(
  case when
  this = 'that' and
  that = 'the other'
  then 1
  else null end) "Count 1",
  count(
  case when
  this = 'this' and
  that = 'that'
  then 1
  else null end) "Count 2",
  count(
  case when
  this = 'confusing'
  then 1
  else null end) "Count 3"
  from
  myTable;

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表