clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1044250 fiddles created (9455 in the last week).

CREATE TABLE T ([no] int, [id] varchar(1)) ; INSERT INTO T ([no], [id]) VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e'), (6, 'f'), (7, 'g'), (8, 'h'), (9, 'i'), (10, 'j'), (11, 'k'), (12, 'l'), (13, 'm') ;
13 rows affected
 hidden batch(es)


with cte as ( select ROW_NUMBER() OVER (ORDER BY T.no) as cus_num ,no,id from T ) select * from cte where cus_num % 5 in (0,1) --我要取每五筆頭尾資料就好 or cus_num = (select max(cus_num) from cte) --,若資料不足五筆,也必須顯示頭尾資料
cus_num no id
1 1 a
5 5 e
6 6 f
10 10 j
11 11 k
13 13 m
 hidden batch(es)