想要查询23号到28号中每天的最后一条数据的集合,该怎么做?

  CREATE TABLE mytable(
  id INT PRIMARY KEY AUTO_INCREMENT,
  myvalue VARCHAR(10),
  mydate DATETIME
  )
  INSERT INTO mytable(myvalue,mydate) VALUES('a','2014-07-22 14:23:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('b','2014-07-22 15:28:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('c','2014-07-23 11:23:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('d','2014-07-25 14:23:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('f','2014-07-26 07:23:00');
INSERT INTO mytable(myvalue,mydate) VALUES('e','2014-07-25 19:26:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('g','2014-07-27 14:23:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('h','2014-07-27 15:23:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('i','2014-07-27 19:51:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('k','2014-07-28 14:23:00');
  INSERT INTO mytable(myvalue,mydate) VALUES('l','2014-07-29 14:23:00');

--查询23号到28号中每天的最后一条数据的集合,即从这张表中筛选出myvalue为c、e、f、i、k
哎呀,想写个sql真是太难了,心好累。

素胚勾勒不出你
浏览 139回答 2
2回答

繁花如伊

兄弟,你这是mysql,开始被你误导啦select a.* from mytable a,(select date(mydate) mydate,max(mydate) max_datetime from mytable where date(mydate) between '2014-07-23' and '2014-07-28' group by date(mydate)) bwhere a.mydate=b.max_datetimeand date(a.mydate)=b.mydate

子衿沉夜

$mysqli->query("SELECT answer FROM FAQ WHERE question="hello"")这句里面出错了,修改的办法有2种:第一把双引号内部的双引号转义:$mysqli->query("SELECT answer FROM FAQ WHERE question=\"hello\"");第二种把双引号变成单引号:$mysqli->query("SELECT answer FROM FAQ WHERE question='hello'");希望对你有所帮助!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL
Oracle