Maison >développement back-end >tutoriel php >php+mysql 取字段值比较 相同则比较另一字段值
MySQL PHP
表结构select * from (select * from tt order by flag desc) t group by mydate;
select id, mydate, max(price) as price, flag from (select * from tbl_name order by price desc) t group by mydate
这个不就是分组查询么?
SELECT * FROM (SELECT * FROM tORDER BY flag DESC , price DESC)ttGROUP BY mydate
楼主是不是先比较flag大小,如果flag大小相同则再比较price大小?试试4楼的方法(其实这个问题我也不会,是完全看得2楼的;我本来想group by xx order by xxx,发现使用了group by 是直接取第一个,后面的order by 好像失效了。也才明白为什么二楼那样写了)
select * from tt a where not exists(select 1 from tt
where a.mydate=mydate and a.flag
a.mydate=mydate and a.flag=flag and a.price
http://bbs.csdn.net/topics/390476456 这个帖子我拿到了sql版块去问了下。确认了下我那方法好像没问题,我今天也也收获呵呵。
楼上的大神很热心,在我那个帖子里回答了,也在这里回答了。但是我们很少这样用。应该是标准SQL语法
to WWWWA:指定日期期间这个条件怎么加上去?
to WWWWA:指定日期期间这个条件怎么加上去?
select * from tt a where not exists(select 1 from tt
where (a.mydate=mydate and a.flag
a.mydate=mydate and a.flag=flag and a.price
)
and a.mydate between '2013-05-30 ' and '2013-06-01 '