使用两个列范围从mysql中选择数据

时间:2016-01-05 09:41:10

标签: mysql sql datetime select str-to-date

我有这样的数据

void MediaListView_ItemClick (object sender, AdapterView.ItemClickEventArgs e)
{
    var song = songList[e.Position];
    var songUri = song.Uri
    mediaPlayer = new MediaPlayer();
    mediaPlayer.SetAudioStreamType (Stream.Music);
    mediaPlayer.SetDataSource (this, songUri);
    mediaPlayer.Prepare ();
    mediaPlayer.Start ();
}

我正在尝试这样的查询

sno name    date        time

1   Irona   2016-01-01  10:00:00
2   Meona   2016-01-02  21:00:00
3   Lessa   2016-01-02  8:00:00
4   Airik   2016-01-03  10:00:00

我希望这些约会在2016-01-02和2016-01-03之间以及晚上9点到10点之间

3 个答案:

答案 0 :(得分:1)

试试这个:

SELECT * 
FROM `appointment` A
WHERE STR_TO_DATE(CONCAT(A.date, ' ', A.time), '%Y-%m-%d %H:%i:%s') BETWEEN '2016-01-02 21:00:00' AND '2016-01-03 10:00:00'

答案 1 :(得分:0)

查询date <= '2016-01-02' and date >= '2016-01-03'不返回任何内容。 你应该把它改成date >= '2016-01-02' and date <= '2016-01-03'

SELECT * FROM `appointment` 
where date >= '2016-01-02' and date <= '2016-01-03' 
and time <= '21:00:00' and time >= '10:00:00'

答案 2 :(得分:0)

我会这样做:

...
WHERE
to_char(date, '%Y%m%d') between '20160102' and '20160103'
AND to_char(timedate, '%H') between '10' and '21'