各位高手,我的需求是。从产品表取12条数据,前8条是分类一的最新的8条(type_id=1),后4条是分类二(type_id=2)的最新的4条数据。请问下各位,这个sql该如何实现。
现在数据表结构为:表名product,id 产品信息id,type_id 产品分类id,请问该如何实现。
用的是mysql数据库。
现在数据表结构为:表名product,id 产品信息id,type_id 产品分类id,请问该如何实现。
用的是mysql数据库。
select * from product where type_id = 1 order by 某字段 desc limit 8
union
select * from product where type_id = 2 order by 某字段 desc limit 4
union all
select * from tb2 order by id desc limit 4
union all
(select * from product where type_id = 2 order by 某字段 desc limit 4);