如何在SQL查询中选择年和月的组合?

时间:2016-11-09 16:41:23

标签: sql sql-server

我需要一些SQL查询的帮助,我需要找到我感兴趣的所有可能的年和月组合。以下是o.orderdate类型为DATETIME的情况。

SELECT 
    o.orderdate
FROM
    Sales.Orders o
WHERE  
    (YEAR(o.orderdate) IN (2007, 2008))
    AND (MONTH(o.orderid) IN (1, 2, 3))
ORDER BY 
    o.orderdate;

我得到的结果是,我们可以看到未选择月份。

2007-07-08 00:00:00.000
2007-07-09 00:00:00.000
2007-07-09 00:00:00.000
2007-07-10 00:00:00.000
2007-07-11 00:00:00.000
2007-07-11 00:00:00.000
2007-07-14 00:00:00.000
2007-07-15 00:00:00.000
2007-07-16 00:00:00.000
2007-07-16 00:00:00.000
2007-07-17 00:00:00.000
2007-07-18 00:00:00.000
2007-07-18 00:00:00.000
2007-07-21 00:00:00.000
2007-07-22 00:00:00.000
2007-07-22 00:00:00.000
2007-07-23 00:00:00.000
2007-07-24 00:00:00.000
2007-07-25 00:00:00.000
2007-07-25 00:00:00.000
2007-07-28 00:00:00.000
2007-07-29 00:00:00.000
2007-07-29 00:00:00.000
2007-07-30 00:00:00.000
2007-07-31 00:00:00.000
2007-07-31 00:00:00.000
2007-08-01 00:00:00.000
2007-08-04 00:00:00.000
2007-08-05 00:00:00.000
2007-08-05 00:00:00.000
2007-08-06 00:00:00.000
2007-08-07 00:00:00.000
2007-08-07 00:00:00.000
2007-08-08 00:00:00.000
2007-08-11 00:00:00.000
2007-08-11 00:00:00.000
2007-08-12 00:00:00.000
2007-08-12 00:00:00.000
2007-08-13 00:00:00.000
2007-08-14 00:00:00.000

2 个答案:

答案 0 :(得分:0)

不应该是//First Activity //This code has no effect right now on the ending position of the transitioned view. public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQ_WHICH_TAB && data != null) { if (ApiLevelHelper.isAtLeast(Build.VERSION_CODES.LOLLIPOP)) { int selectedTab = data.getIntExtra("selected_tab", 0); setTransitionName(selectedTab); //This call nullifies all transition names //and sets it back to the right ImageView. //But it doesn't work. } } super.onActivityResult(requestCode, resultCode, data); } 而不是orderdate吗?

orderid

答案 1 :(得分:0)

您已将错误的参数放入应该

的MONTH()函数中
entry_1.bind("<Return>",lambda :entry_2.focus_set())

或者,如果您选择日期范围内的日期,最好使用带有完整日期的不等式

SELECT
  o.orderdate
FROM Sales.Orders o
WHERE (YEAR(o.orderdate) IN (2007, 2008))
  AND (MONTH(o.orderdate) IN (1, 2, 3))
 ORDER BY o.orderdate;