SQLITE SELECT一个Date Integer列如果该Date的所有记录在另一个参数中都是NULL

时间:2011-08-02 09:40:01

标签: sqlite select null group-by

我可能以错误的方式接近......

我的格式为INTEGER的日期格式为yyyymmdd - 名为DateInteger 我有另一个字段Method,默认情况下为NULL。该字段由各种查询更新。 我想制作一份报告,说明所有Method字段为NULL的日期(按DateInteger分组/排序)。

`SELECT DateInteger,COUNT(*) FROM Table WHERE Method IS NOT NULL GROUP BY DateInteger HAVING Count(*)=0 ORDER BY DateInteger ASC;` doesn't give any results, as the days which have only `NULL` values seem to be missed out...

如何让查询包含/查看这些日子?

TIA

1 个答案:

答案 0 :(得分:0)

I'd like to produce a report that illustrates the days where ALL the Method fields are NULL (Grouping/Ordering by DateInteger).

这将返回一组不同的日期字段值,其中方法列值 null:

            select distinct yourDateField from yourTable 
           where method is not null

如果我理解你,上面的这些日期字段值是你想要的那些:你需要每一行中给定日期的所有方法值都为null。因此, 想要的日期字段值不能在上面的集合中。

          select T.yourDateField, NotWanted.Unwanted
          from yourTable as T
          left join
          (
            select distinct yourDateField as Unwanted from yourTable 
           where method is not null
          ) as NotWanted

          on T.yourDateField = NotWanted.Unwanted

          where NotWanted.Unwanted is null
编辑:你也可以试试这个:

        select T.yourDateField from yourTable as T
        where not exists
        (
           select yourDateField from yourTable as T2
           where T1.yourDateField = T2.yourDateField
           and T2.method is not null

        )