我想在我的表中使用客户ID订购的每个Customer组之前添加一行。是否可以使用FIRST_VALUE()或其他技术?
答案 0 :(得分:0)
declare @customer table (id int, name varchar(500));
insert into @customer (id, name) values
(1, 'Client1'),
(2, 'Client2'),
(3, 'Client3'),
(4, 'Client4');
select
c.id, c.name, 2 ord
from
@customer c
union all
select
c.id, 'some new value before', 1 ord
from
@customer c
order by
id, ord
;