i have this table
CREATE TABLE IF NOT EXISTS `goldprice` (
`price` double unsigned NOT NULL,
`days` smallint(5) unsigned NOT NULL,
`seconds` mediumint(5) unsigned NOT NULL,
`sid` smallint(4) unsigned NOT NULL,
`gid` smallint(4) NOT NULL,
PRIMARY KEY (`days`,`seconds`,`sid`),
KEY `sid` (`sid`),
KEY `gid` (`gid`),
KEY `days` (`days`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and i want minimum and maximum price of each day first and last price of each day (base on its seconds) with using subquery i can solve some part of my problem before grouping i make a subquery and sorting in it result in mysql is true min, max, and last or first (based on sort type) can be made two important things remains last and first both is required performance is very important subquery seems not good
and i have his sql
SELECT price, days, seconds FROM goldprice
where gid=1 and days>=16200 group by days
order by days desc, seconds desc
change "days>=16200" to "days=16200" will returns different result in "days=16200" row.
the sort is not remaining desc.
i know behavior of my sql group by
but i can't find good solution for my needs