创建表:
CREATE TABLE `ind_tom_15_14` (
`id` bigint(16) NOT NULL AUTO_INCREMENT,
`moentityid` bigint(16) DEFAULT NULL,
`startday` int(6) DEFAULT NULL,
`ind_tom_15_14_001` decimal(14,4) DEFAULT NULL
)
添加数据:
INSERT INTO `ind_tom_15_14` (`id`, `moentityid`, `startday`,
`ind_tom_15_14_001` ) VALUES ('1586940625258862', '10030', '20200301',
'0.0000');
INSERT INTO `ind_tom_15_14` (`id`, `moentityid`, `startday`,
`ind_tom_15_14_001` ) VALUES ('1586940625258863', '10030', '20200401',
'0.0000');
INSERT INTO `ind_tom_15_14` (`id`, `moentityid`, `startday`,
`ind_tom_15_14_001` ) VALUES ('1586940625258864', '10031', '20200301',
'0.0000');
INSERT INTO `ind_tom_15_14` (`id`, `moentityid`, `startday`,
`ind_tom_15_14_001` ) VALUES ('1586940625258865', '10031', '20200401',
'0.0000');
第一种查询方式:
SELECT bb.ind_tom_15_14_001 ,bb.moentityid from ind_tom_15_14 bb
LEFT JOIN (
select MAX(aa.startday) startday,aa.moentityid from ind_tom_15_14 aa
GROUP BY aa.moentityid
) cc
on cc.moentityid=bb.moentityid
WHERE bb.startday=cc.startday
第二种查询方式:
SELECT * from (
SELECT
@row_num := IF(@prev_value=o.moentityid,@row_num+1,1) AS RowNumber
,o.moentityid ,o.ind_tom_15_14_001,o.startday
,@prev_value := o.moentityid
FROM ind_tom_15_14 o,
(SELECT @row_num := 1) x,
(SELECT @prev_value := '') y
ORDER BY o.moentityid desc, o.startday
desc
) t where t.RowNumber = 1
最后
以上就是专一短靴最近收集整理的关于mysql 查询多条数据最新数据的全部内容,更多相关mysql内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复