SELECT TOP 1000 [ID]
      ,[SourcePageID]
      ,[PlatformType]
      ,[CreateTime]
  FROM [home_sendorder].[dbo].[ApplyUser]
where [PlatformType]=2 and [CreateTime]>='2015-10-28' and [CreateTime]<='2015-11-1'
注意这样写,只是从28号0点查到1号0点

----------------------------------------------------------------------------------------------

当条件为下时,跟datediff()查询的结果一样

where [PlatformType]=2 and [CreateTime]>='2015-10-28' and [CreateTime]<'2015-11-2')

SELECT TOP 1000 [ID]
      ,[SourcePageID]
      ,[PlatformType]
      ,[CreateTime]
  FROM [home_sendorder].[dbo].[ApplyUser]
where [PlatformType]=2 and datediff(day,'11/1/2015',[CreateTime])<=0 and datediff(day,'10/28/2015',[CreateTime])>=0

------------------------------------------------------------------------------------------------------------------------------

select [SourcePageID],count(*) from [ApplyUser]
where [PlatformType]=2 and datediff(day,'11/1/2015',[CreateTime])<=0 and datediff(day,'10/28/2015',[CreateTime])>=0
group by [SourcePageID]
注意:以上写法是ApplyUser内有的信息为依据,查询出的结果。如图:当SourcePageID=5时候,ApplyUser表里面没有,所以不显示。

--------------------------------------------------------------------------------------------------

所以想查询到SourcePageID的全部数据,就要找到  有SourcePageID的全部数据  的表 作为基本表

select b.[SourcePageID], b.[SourcePageName],count(a.id) from [SourceUserPageConfig] b--基本表
 left  join [ApplyUser]a---或inner join
 on  (b.[PlatformType]=a.[PlatformType]  and b.[SourcePageID]=a.[SourcePageID])
where b.[PlatformType]=2
 and datediff(day,'11/1/2015',a.[CreateTime])<=0
 and datediff(day,'10/28/2015',a.[CreateTime])>=0
group by b.[SourcePageID], b.[SourcePageName]

order by  b.[SourcePageID] asc

还是没有5,感觉应该是不满足where条件,被删除

但是怎样才能把5这行数据显示出来,有5---0这一行。

请高手指点

SQL 取两日期的记录的更多相关文章

  1. Java和SQL取两个字符间的值

    Java String str = "abcdefg"; String result = str.substring(str.indexOf(">")+1 ...

  2. SQL表两列取一列唯一值的记录

    问下SQL表两列取一列唯一值的 A列         B列       C列 1001      AA      2012-01-02 1001      BB      2012-02-05 100 ...

  3. 记一个常见的ms sql server中取第N条记录的方法

    前言 好好学习,天天向上. 正文 好像也是一个不难的问题,刚视频里看到的,就记一下吧. 下面是表中原始的数据结构,做了一个倒叙排序: select * from Employee order by S ...

  4. Sql语句groupBY分组后取最新一条记录的SQL

    一.问题 groupBY分组后取最新一条记录的SQL的解决方案. 二.解决方案 select Message,EventTime from PT_ChildSysAlarms as a where E ...

  5. 【HANA系列】SAP HANA SQL计算两个日期的差值

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL计算两个 ...

  6. SQL Server中取两个表的交集,并集和差集

    在项目中遇到要取两个表差集的情况 假设有两个表tblNZPostCodes, NZPostcode  两个表中存储的都是新西兰的post code信息,字段一致,只是数据上有所差异. 1. Union ...

  7. oracle 取前10条记录

    1.oracle 取前10条记录 1) select * from tbname where rownum < 11; 2) select * from (select * from tbnam ...

  8. 使用sql语句查询日期在一定时间内的数据

    使用sql语句查询日期在一周内的数据 select * from ShopOrder where datediff(week,ordTime,getdate()-1)=0   //查询当天日期在一周年 ...

  9. Oracle 取两个表中数据的交集并集差异集合

    Oracle 取两个表中数据的交集 关键字: Oracle 取两个表中数据的交集 INTERSECT Oracle 作为一个大型的关系数据库,日常应用中往往需要提取两个表的交集数据 例如现有如下表,要 ...

随机推荐

  1. ECMAScript6新特性之Array API

    一 填充数组 var arr = new Array(5); arr.fill('abc',2,4); console.log('Array.prototype.fill',arr); // [und ...

  2. swift - 网络请求数据处理 - 协议处理

    1. 在类的模型之中或类的结构体 里面 实现下面方法 /// 添加预约数据源模型 - rootModel class DataModelForAddNewBespeakModel: NSObject ...

  3. [leetcode]349. Intersection of Two Arrays数组交集

    Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...

  4. 6-Linux 上mysql的常用命令 以及 tomcat的相关指定

    mysql -u root -p 进入Mysql //注意一下有逗号!!! show databases; //显示所有的数据库 drop database mydb; // 删除mydb这个数据库 ...

  5. 7-找了一上午的BUG

    #include <iostream>#include <cstring>#include <algorithm>#define MAX 1<<28;u ...

  6. adf常用方法总结

    1.使用clientAttribute传值.获取值 或组件上面放客户端属性 <af:selectBooleanCheckbox text="" label="&qu ...

  7. MVC中构建Linq条件、排序、Selector字段过滤

    代码: System.Linq.Expressions.Expression<Func<Domain.S_ROLE, bool>> expressWhere1 = (c =&g ...

  8. Tornado异步阻塞解决方案

    在 tornado 中异步无阻塞的执行耗时任务 在 linux 上 tornado 是基于 epoll 的事件驱动框架,在网络事件上是无阻塞的.但是因为 tornado 自身是单线程的,所以如果我们在 ...

  9. code4906 删数问题

    题目: 键盘输入一个高精度的正整数n(<=240位), 去掉任意s个数字后剩下的数字按原左右次序将组成一个新的正整数. 编程对给定的n和s,寻找一种方案,使得剩下的数最小. Simple Inp ...

  10. dedecms模型类的引入