简体   繁体   English

MySql计算日期行中包含(NULL)和'0000-00-00'值的所有元组

[英]MySql counting all those tupples where in Date Rows containing (NULL) and or '0000-00-00' values

i want to count all those rows from mysql table where in the "where clause" three columns having two possible values in it. 我想从mysql表中的“ where子句”中的三列中计算出所有可能的值。 ie ( NULL ) and OR 0000-00-00 . 即( NULL )和OR 0000-00-00 For this i have written the following sql which returns a result where i am not sure it is a perfect sql query or not. 为此,我编写了以下sql,该sql返回的结果不确定我是否是理想的sql查询。 Please guide me if i am doing wrong. 如果我做错了,请指导我。

      SELECT 
          COUNT(sno) AS totalCases 
      FROM
         myTable
       WHERE (dateOfTransferInstituion IS NULL OR dateOfTransferInstituion = '0000-00-00')
         AND 
             (date_remanded IS NULL OR date_remanded = '0000-00-00')
         AND 
             (date_restored IS NULL OR date_restored = '0000-00-00')

Thanks in advance. 提前致谢。

I have read your task and I think your query is correct, but it is possible to do it more elegantly, like this : 我已经阅读了您的任务,并且我认为您的查询是正确的,但是可以更优雅地做到这一点,例如:

  SELECT 
      COUNT(sno) AS totalCases 
  FROM
     myTable
   WHERE IFNULL(dateOfTransferInstituion,'0000-00-00') = '0000-00-00'
     AND 
         IFNULL(date_remanded,'0000-00-00') = '0000-00-00'
     AND 
         IFNULL(date_restored,'0000-00-00') = '0000-00-00'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM