sql根据日期

时间:2018-05-01 16:01:21

标签: sql-server-2008

当前查询:

SELECT TOP 1 * FROM
 (SELECT B.FILEKEY, B.STATUS AS STATUS, B.EFFDATE FROM TABLEB B
  UNION
  SELECT A.FILEKEY, A.STATUS2 AS STATUS, A.EFFDATE2 AS EFFDATE FROM TABLEA A) C
WHERE C.EFFDATE <= '5/1/2011')
ORDER BY C.EFFDATE DESC

产生正确的结果:

 Status Filekey  Effdate
    0      1       2011-01-01 00:00:00.000

基于联合表C:

Filekey    Status    Effdate
  1           0         2013-01-01 00:00:00.000
  1           1         2012-01-01 00:00:00.000
  1           0         2011-01-01 00:00:00.000
  1           1         2010-01-01 00:00:00.000
  1           0         2009-01-01 00:00:00.000

我现在需要添加一个新因素:截至特定日期的位置。

联合表F的生成如下:

(SELECT E.FILEKEY, E.location, E.EFFDATE FROM TABLEE E
  UNION
  SELECT D.FILEKEY, D.location, D.LOCEFFDATE2 AS EFFDATE FROM TABLED D) F

我真正想要得到的是以下结果: Filekey,Status,Location全部基于特定日期

截至特定日期,文件密钥的状态和位置是什么?

感谢您的帮助。预期的输出看起来像:

Filekey      Status     Location
  1            0           2

1 个答案:

答案 0 :(得分:0)

终于明白了:

<!-- Base application theme. -->
<style name="Theme.Noteplus.Base.Brown" parent="Theme.AppCompat.Light.DarkActionBar">

    <item name="actionModeStyle">@style/Widget.ActionMode</item>

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>