表结构
id int 主健自增
mydate datetime
price int
flag int 数值为1,2,3,4,5,6 优先取该值大的price
示例
id mydate price flag
1 2013-05-30 200 2
2 2013-05-30 300 3
3 2013-05-31 150 2
4 2013-05-31 200 3
5 2013-06-01 200 2
6 2013-06-01 300 3结果为
id mydate price flag
1 2013-05-30 300 3
2 2013-05-31 200 3
3 2013-06-01 350 3
php代码如何写?很久没写过php代码了,先谢过MySQLPHP
id int 主健自增
mydate datetime
price int
flag int 数值为1,2,3,4,5,6 优先取该值大的price
示例
id mydate price flag
1 2013-05-30 200 2
2 2013-05-30 300 3
3 2013-05-31 150 2
4 2013-05-31 200 3
5 2013-06-01 200 2
6 2013-06-01 300 3结果为
id mydate price flag
1 2013-05-30 300 3
2 2013-05-31 200 3
3 2013-06-01 350 3
php代码如何写?很久没写过php代码了,先谢过MySQLPHP
解决方案 »
- PHP无限分类 不知道问题出现在那里了
- 我的服务器放在防火墙的DMZ区,服务器上通过$_SERVER['REMOTE_ADDR']取不到访问者的IP,取的是防火墙的公网IP?
- 来源关键词记录,在线等
- 调用类的问题
- 请问这个出什么毛病了(有一列数据无法显示 JSON)
- url传递单个变量时如何省略变量名?
- 请教 怎么统计select avg(fen) as 平均分 from userdatefen where userid="&rs("userid")最后5次
- 为什么验证码无法显示?
- apache+php+mysql +win平台,对无盘工作站的支持。
- 为什么我的php页面之间无法传递信息?
- php截取特定段落如何操作
- 正则,快来帮忙。。
FROM (SELECT *
FROM t
ORDER BY flag DESC , price DESC
)tt
GROUP BY mydate
where a.mydate=mydate and a.flag<flag
or
a.mydate=mydate and a.flag=flag and a.price<price
)
楼上的大神很热心,在我那个帖子里回答了,也在这里回答了。但是我们很少这样用。应该是标准SQL语法
select * from tt a where not exists(select 1 from tt
where (a.mydate=mydate and a.flag<flag
or
a.mydate=mydate and a.flag=flag and a.price<price)
and mydate between '2013-05-30 ' and '2013-06-01 '
)
and a.mydate between '2013-05-30 ' and '2013-06-01 '