Answer the question
In order to leave comments, you need to log in
How to group query in mysql by minimum value?
CREATE TABLE `cdr` (
`uniqueid` varchar(32) NOT NULL DEFAULT '',
`userfield` varchar(255) NOT NULL DEFAULT '',
`progressiveid` int(11) NOT NULL AUTO_INCREMENT,
`accountcode` varchar(20) NOT NULL DEFAULT '',
`src` varchar(80) NOT NULL DEFAULT '',
`dst` varchar(80) NOT NULL DEFAULT '',
`dcontext` varchar(80) NOT NULL DEFAULT '',
`clid` varchar( 80) NOT NULL DEFAULT '',
`channel` varchar(80) NOT NULL DEFAULT '',
`dstchannel` varchar(80) NOT NULL DEFAULT '',
`lastapp` varchar(80) NOT NULL DEFAULT '',
`lastdata` varchar(80) NOT NULL DEFAULT '',
`calldate` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`duration` int(11) NOT NULL DEFAULT '0',
`billsec` int(11) NOT NULL DEFAULT '0',
`disposition` varchar(45) NOT NULL DEFAULT '',
`amaflags` int(11) NOT NULL DEFAULT '0',
`callend` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`peeraccount` varchar(20) NOT NULL,
`linked` varchar(32) NOT NULL,
`sequence` int(11) NOT NULL DEFAULT '0',
) ENGINE =MyISAM AUTO_INCREMENT=139232 DEFAULT CHARSET=latin1;
The table contains the call log from asterisk.
How to group by linkedid, but in such a way as to get the minimum sequence value corresponding to these rows?
Answer the question
In order to leave comments, you need to log in
select * from `cdr` join (
SELECT `linkedid` as `minlinkedid`, MIN(`sequence`) as minseq
FROM `cdr`
GROUP BY `linkedid`) as minsequences on sequence=minseq and `linkedid`=`minlinkedid`
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question