在SQL语句中使用最大和给定日期获取错误 [英] Getting Error using Max and Given Date in SQL Statement

查看:93
本文介绍了在SQL语句中使用最大和给定日期获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要查询日期和日期之间的数据.

Bur,使用以下查询时出现错误.

我想从日期给出日期和最大日期"中获取结果,并且
在给定日期和最大日期"之间的日期

如何编写查询或形成查询...?

查看我的示例查询
-------------------

I want query between from date and to date.

Bur,i am getting error when i use below query.

I want to get result from date beteen "Given date and Max Date" and
To Date between "Given date and Max Date"

How to write Query or form the query...?

See my sample query
-------------------

select * FROM (
  SELECT datefrom AS datefrm, *
  FROM LM_TblLeaveapply
  WHERE datefrom between '2011-10-24' and (select Max(datefrom) from LM_TblLeaveapply)
) t1
FULL OUTER JOIN
 (
 SELECT dateto AS datto, *
  FROM LM_TblLeaveapply
  where dateto between '2011-10-24' and (select Max(dateto) from LM_TblLeaveapply)
) t2




样本数据:

EmpId DateFrom DateTo
101 20-10-2010 20-10-2010
101 21-10-2010 21-10-2010
101 22-10-2010 22-10-2010
101 23-10-2010 23-10-2010
24-10-2011 24-10-2011
25-10-2011 25-10-2011
23-05-2012 23-05-2012




sample data :

EmpId DateFrom DateTo
101 20-10-2010 20-10-2010
101 21-10-2010 21-10-2010
101 22-10-2010 22-10-2010
101 23-10-2010 23-10-2010
24-10-2011 24-10-2011
25-10-2011 25-10-2011
23-05-2012 23-05-2012

推荐答案

查询中的错误是

您正在使用联接查询,因此您必须在满足条件的情况下输入t1和t2的公共键

例子.

The Error in Query is

You are making use of a join query so u have to make a common key of t1 and t2 in on condition

example.

select t1.*,t2.* FROM (
  SELECT datefrom AS datefrm, *
  FROM LM_TblLeaveapply
  WHERE datefrom between '2010-10-19' and (select Max(datefrom) from LM_TblLeaveapply)
) t1
FULL OUTER JOIN
 (
 SELECT dateto AS datto, *
  FROM LM_TblLeaveapply
  where dateto between '2010-10-19' and (select Max(dateto) from LM_TblLeaveapply)
) t2 on t1.empid = t2.empid



这是要运行此查询.但仍然不知道结果如何.



This is to run this query. but still dont know what u want as result.


这篇关于在SQL语句中使用最大和给定日期获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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