If you ever want to conditionally count the number of times a particular condition occurs in SQL, you can do it in Oracle using the case andcount functions. Here's a simple example which counts the number of males/females stored in PS_PERSONAL_DATA.

select count(case when SEX = 'M' then 1 end) as MALES, count(case when SEX = 'F' then 1 end) asFEMALESfrom PS_PERSONAL_DATA

All that is happening is that the case statement returns a 1 for every instance where the gender is M or F and the count, counts each returned value of 1 giving a summary like this:

MALES FEMALES
10004 20421

The conditions in the case statement can be a lot more complex and can include sub-queries.

Conditional Counting In SQL的更多相关文章

  1. pl/sql tutorial

    http://plsql-tutorial.com/plsql-procedures.htm What is PL/SQL? PL/SQL stands for Procedural Language ...

  2. Portswigger web security academy:SQL injection

    Portswigger web security academy:SQL injection 目录 Portswigger web security academy:SQL injection SQL ...

  3. (转载)SQL Reporting Services (Expression Examples)

    https://msdn.microsoft.com/en-us/library/ms157328(v=SQL.100).aspx Expressions are used frequently in ...

  4. 如何知道SQL Server机器上有多少个NUMA节点

    如何知道SQL Server机器上有多少个NUMA节点 文章出处: How can you tell how many NUMA nodes your SQL Server has? http://i ...

  5. EntityFramework 如何查看执行的 SQL 代码?

    在 VS 调试的时候,如果我们项目中使用的是 EntityFramework,查看 SQL 执行代码就不像 ADO.NET 那样直观了,我们需要设置下,可以参考下: How can I log the ...

  6. SQL for SQLite

    语法 verb + subject + predicate commannds(命令) SQL由命令组成,以分号为结束.命令有token组成,token由white space分隔,包括空格.tab. ...

  7. SQLite Learning、SQL Query Optimization In Multiple Rule

    catalog . SQLite简介 . Sqlite安装 . SQLite Programing . SQLite statements 1. SQLite简介 SQLite是一款轻型的数据库,是遵 ...

  8. MONGODB 与sql聚合操作对应图

    MongoDB 高级查询条件操作符 2012-04-25 15:35:19|  分类: MongoDB |  标签:mongodb使用  mongodb查询  |举报|字号 订阅 http://blo ...

  9. P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

    P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May ...

随机推荐

  1. 总结Ajax跨域调用问题

    原文:http://blog.csdn.net/wangxiaohu__/article/details/7294842 (一):动态脚本注入的方法.即在页面中动态生成<script>脚本 ...

  2. [DataTable]C# datatable取最大值最小值

    ArrayList al = new ArrayList(); DataTable dt = new DataTable(); dt.Columns.Add("A",typeof( ...

  3. C++primer 练习11.33:实现你自己版本的单词转换程序

    // 11_33.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  4. es增量自定义更新的脚本

    安装需要可软件 sudo apt-get install python-pip sudo pip install elasticsearch; sudo apt-get install python- ...

  5. What is the Database Initialization Parameter That is Associated to an ORA-32004 Error ?

    APPLIES TO: Oracle Database - Enterprise Edition - Version 9.2.0.1 to 11.2.0.3 [Release 9.2 to 11.2] ...

  6. JQuery基础教程:事件(下)

     事件传播     为了说明不可单击的页面元素处理单击事件的能力,例如样式转换器中包含按钮的div元素或者兄弟元素h3,我们来实现一个鼠标指针进入元素和离开元素时的效果,首先需要添加一种翻转状态,表明 ...

  7. IEnumerable和List有什么区别?

    如下.IList接口可以使用更多的方法.比如你看一个集合是否包含相应实体, IEnumerable不行,而 IList里有Contains,相应的实现了IList的可以添加,删除相应实体.而IEnum ...

  8. Drupal常用开发工具(一)——Devel模块

    进行 Drupal 开发时有许多模块和工具可供使用,其中最常用的两项便是 Devel 及 Drupal for Firebug.本文和<Drupal常用开发工具(二)——Drupal for F ...

  9. Android开发-API指南-<data>

    <data> 英文原文:http://developer.android.com/guide/topics/manifest/data-element.html 采集(更新)日期:2014 ...

  10. jQuery中 wrap() wrapAll() 与 wrapInner()的区别

    今晚看书的时候发现jQuery有三个包裹节点的方法,百度了一下jQuery wrap() / wrapAll() / wrapInner(),果然搜索结果 W3School的文档说明是排第一的. 可是 ...