mysql分組取每組前幾條記錄

2021-09-05 11:27:03 字數 2407 閱讀 5449

drop table if exists `ho_archives`;

create table `ho_archives` (

`id` mediumint(11) unsigned not null auto_increment comment '自增id',

`type` smallint(5) unsigned not null default '0' comment '所屬欄目',

`title` varchar(80) not null default '' comment '標題 ',

`senddate` int(10) unsigned not null default '0' comment '發布時間',

`isdelete` tinyint(11) not null default '0' comment '邏輯刪除狀態0:不刪除1:假刪除',

primary key (`id`),

key `arctypeid` (`type`)

) engine=myisam auto_increment=19 default charset=utf8 row_format=dynamic comment='文件自定義屬性表';

insert into `ho_archives` values ('1', '16', '**漏洞檢測服務', '1379300153', '0');

insert into `ho_archives` values ('3', '16', '**安全監控', '1379300340', '0');

insert into `ho_archives` values ('4', '16', '**應急響應服務', '1379300358', '0');

insert into `ho_archives` values ('5', '16', '****加固', '1379300370', '0');

insert into `ho_archives` values ('6', '14', '**伺服器安全加固', '1379300782', '0');

insert into `ho_archives` values ('7', '14', '國內資訊保安存5大盲區', '1379397987', '0');

insert into `ho_archives` values ('8', '14', 'gartner揭示十大it安全誤區', '1379398105', '0');

insert into `ho_archives` values ('9', '14', '黑客組織「匿名者」威脅', '1383567878', '0');

insert into `ho_archives` values ('10', '17', '**安全服務專案-安全檢測授權書', '1384131921', '0');

insert into `ho_archives` values ('11', '17', '**安全服務專案-安全檢測授權書', '1384132192', '0');

insert into `ho_archives` values ('12', '17', '如何利用google機械人進行sql攻擊', '1384149836', '0');

insert into `ho_archives` values ('13', '17', '**安全服務專案-安全檢測授權書', '1384161419', '0');

insert into `ho_archives` values ('14', '13', '對於即將出台的等保標準', '1533605926', '0');

insert into `ho_archives` values ('15', '13', '《網路安全法實施指南 、一》', '1533611060', '0');

insert into `ho_archives` values ('16', '13', '《網路安全法實施指南、二》', '1533612538', '0');

insert into `ho_archives` values ('17', '13', '《國家網路空間安全戰略》全文', '1533623084', '0');

insert into `ho_archives` values ('18', '13', '《國家網路安全事件應急預案》', '1533624631', '0');

SQL分組取每組前一 或幾 條記錄 排名

use test go object table dbo scores script date 2018 3 11 17 59 15 set ansi nulls on goset quoted identifier on goset ansi padding on gocreate table d...

SQL分組取每組前幾條記錄,剩下的列為其他

sqlserver 寫法 select from lx dbo 全國銷售額 where province 北京 group by province name 按銷售額排序 取每個省的前4名,剩下的為其他 select from select a.province,a.name a.value fro...

MySQL 分組後取前幾條

利用group concat和substring index實現,能很好的利用索引,適合大資料。select from yourtable where id in select substring index group concat id order by column 2 desc 1 id f...