sql ..动态检索每月记录

时间:2017-05-04 20:42:22

标签: sql

SQL问题...我想要一个SQL查询来动态捕获月度记录

示例数据:

PYear   PDate           PMonth
2017    2/22/2017   February
2017    1/24/2017   January
2017    1/24/2017   January
2017    1/24/2017   January
2017    1/24/2017   January
2017    1/24/2017   January
2017    1/17/2017   January
2017    1/11/2017   January
2017    1/24/2017   January
2017    3/21/2017   March
2017    3/21/2017   March

我希望输出能够捕获每月记录。只记录三月份的记录

2 个答案:

答案 0 :(得分:1)

也许像下面这样的简单查询就是你要找的东西:

setInterval(attemptConnection, 3000);

function attemptConnection() {
    var exampleSocket = new WebSocket("ws://localhost:8080");
    exampleSocket.onmessage = function (event) {
        var JsonObject = JSON.parse(event.data);
        document.getElementById(JsonObject.elementTagValue).setAttribute("value", JsonObject.valueToSet);
        exampleSocket.send(event.data);

        exampleSocket.onerror = function () {
            //do nothing
        }
    }
}

select * from myTable where PMonth='March`

答案 1 :(得分:1)

此查询将为您提供当前月份的表格数据。将“YourTable”替换为您的表名。假设您的PDate列是日期类型之一。

SELECT PYear, PDate, PMonth
FROM YourTable
WHERE DATEPART(MM, PDate) = DATEPART(MM, GETDATE())