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真是太难了,心好累。
2 回答
繁花如伊
TA贡献2012条经验 获得超12个赞
兄弟,你这是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)) b where a.mydate=b.max_datetime and date (a.mydate)=b.mydate |
子衿沉夜
TA贡献1828条经验 获得超3个赞
$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'");希望对你有所帮助!
添加回答
举报
0/150
提交
取消