如何从数据库中计算空值...? [英] How to count a null Values From the Database...?

查看:263
本文介绍了如何从数据库中计算空值...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有CheckIn和CheckOut文件的表.
我想算一次总尝试次数.

条目将是这样..

签入签出
2011-09-29 17:27:59. 653  2008-11-29 17:35:50. 020 
 NULL  2008-11-29 18:07:49. 653 
2008-11-29 17:27:59. 653   NULL  



当我尝试计算像
这样的总尝试次数时

 选择 COUNT(CheckIn)来自出勤


那么它将仅在2中产生结果

但是实际上我的要求是,即使CheckIn为null并且CheckOut字段包含任何条目,也将被计数

因此,当我触发查询以计算总尝试次数时,将在上述数据中产生3..


在此先感谢..
Tejas Vaishnav

解决方案

空值不算作条目-可以理解-COUNT函数会忽略它们.
而是使用``*'':

  SELECT  COUNT(*) FROM 出勤率


亲爱的
试试这个代码.

从签到不为空的出勤者中选择COUNT(CheckIn)

从不是Checkout的出勤者中选择COUNT(CheckOut)
null


您可以使用is null子句进行检查

表列或任何变量中存在空值.


I have a Table with a CheckIn and CheckOut Fileds.
I want to Count a Total Attempt..

The Entrys will be like this..

CheckIn                      CheckOut
2011-09-29 17:27:59.653      2008-11-29 17:35:50.020
NULL                         2008-11-29 18:07:49.653
2008-11-29 17:27:59.653      NULL



When I try to count total attempt like

SELECT COUNT(CheckIn) From Attendance


Then it will be Resulted in Only 2

But actually my Requirement is that even if CheckIn is null and the CheckOut filed is contain any entry then it will be counted

so when i fire a query for counting total attempt then it will be resulted in 3 on above data..


Thanks in Advance..
Tejas Vaishnav

解决方案

Null values are not counted as entries - understandably - so the COUNT function ignores them.
Instead use ''*'':

SELECT COUNT(*) FROM Attendance


Dear
Try this code.

SELECT COUNT(CheckIn) From Attendance where CheckIn is not null

SELECT COUNT(CheckOut) From Attendance where Checkout is not
null


You can use is null clause for checking

null value existence in table column or any variable.


这篇关于如何从数据库中计算空值...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆