从具有日期间隔MySql PHP的表中选择数据

时间:2017-01-10 12:14:34

标签: mysql date

这是我的名为Movies的表格,其中包含以下数据:

movie_id | movie_title |  movie_Date  | views  |
---------+-------------+--------------+--------+
1        | Movie 1     |2016-03-10    | 15     |
2        | Movie 2     |2016-02-14    | 12     |
3        | Movie 3     |2016-01-27    | 50     |
4        | Movie 4     |2016-01-21    | 13     |
5        | Movie 5     |2015-12-30    | 10     |
6        | Movie 6     |2015-12-27    | 83     |


我的疑问是:

SELECT * FROM Movies WHERE (a date interval based on movie_date and the current system date) ORDER BY views DESC LIMIT 5

我想修改我的查询,只选择具有指定日期间隔的电影。

5 个答案:

答案 0 :(得分:2)

您也可以尝试:

2.02 4.07
5.03 4.0
6.02 3.57
8.07 2.145
4.02 2.09
9.1 2.04
10.11 2.02
7.06 2.012
1.04 2.01
3.03 1.08

这是最好的方法。享受。

答案 1 :(得分:1)

您可以使用between

SELECT * FROM Movies WHERE movie_date BETWEEN startDate AND endDate ORDER BY views DESC LIMIT 5

答案 2 :(得分:0)

将您的查询更改为此类

SELECT * FROM Movies WHERE (movie_Date >= startDate and movie_Date <= endDate) ORDER BY views DESC LIMIT 5

其中startDateendDate给出您指定的日期间隔。

那应该这样做

答案 3 :(得分:0)

var module = angular.module("filter", []);
 module.controller("filterController", function($scope) {
$scope.elements={};
$scope.optionString = "e[name] for e in elements";
 var data = [
   {
       name:"Robin",
       dob:new Date("March, 23, 1980"),
       gender:"male",
       salary:70000
   },
   {
       name:"John",
       dob:new Date("January, 23, 1981"),
       gender:"male",
       salary:65000
   },
   {
       name:"Ruby",
       dob:new Date("March, 24, 1982"),
       gender:"female",
       salary:55000
   }
]

$scope.data = data;

$scope.getSelectedIndex =  function() {
   var index = $scope.idx - 1;
   var obj = $scope.data[index];
   for(o in obj) {
       $scope.elements[o] = obj[o];
   }
   console.log($scope.elements)
}
});

答案 4 :(得分:0)

我认为你需要这个:

app.get('/version', (req, res) => {
    let pack = require('../package.json');
    res.send(pack.version);
});

希望这有帮助