可以用查詢的方式去新增..
declare @Test table(
Test_ID int
,Test_Txt nvarchar(5)
,Test_Count int
)
insert into @Test
select Set_ID
,Set_Txt
,isNull((select count(*) from @Test where Set_ID >= Test_ID and Set_Txt = Test_Txt),0)+1 as Set_Count
from (
select isNull((select max(Test_ID) from @Test),0) + 1 as Set_ID
,'A' as Set_Txt
) as k
insert into @Test
select Set_ID
,Set_Txt
,isNull((select count(*) from @Test where Set_ID >= Test_ID and Set_Txt = Test_Txt),0)+1 as Set_Count
from (
select isNull((select max(Test_ID) from @Test),0) + 1 as Set_ID
,'B' as Set_Txt
) as k
insert into @Test
select Set_ID
,Set_Txt
,isNull((select count(*) from @Test where Set_ID >= Test_ID and Set_Txt = Test_Txt),0)+1 as Set_Count
from (
select isNull((select max(Test_ID) from @Test),0) + 1 as Set_ID
,'C' as Set_Txt
) as k
insert into @Test
select Set_ID
,Set_Txt
,isNull((select count(*) from @Test where Set_ID >= Test_ID and Set_Txt = Test_Txt),0)+1 as Set_Count
from (
select isNull((select max(Test_ID) from @Test),0) + 1 as Set_ID
,'B' as Set_Txt
) as k
insert into @Test
select Set_ID
,Set_Txt
,isNull((select count(*) from @Test where Set_ID >= Test_ID and Set_Txt = Test_Txt),0)+1 as Set_Count
from (
select isNull((select max(Test_ID) from @Test),0) + 1 as Set_ID
,'C' as Set_Txt
) as k
insert into @Test
select Set_ID
,Set_Txt
,isNull((select count(*) from @Test where Set_ID >= Test_ID and Set_Txt = Test_Txt),0)+1 as Set_Count
from (
select isNull((select max(Test_ID) from @Test),0) + 1 as Set_ID
,'C' as Set_Txt
) as k
select * from @Test
一般來說是不太可能直接這樣用。
只能利用後端程式,來寫程式處理。或是sql的事件功能函式來幫你處理了。
當然用「純真的人」給你用的方式也是一種方法。
其實這方法只是利用了sql來寫程式處理。也算是一招就是了。
我的作法是這樣:
1.先建一個函數GetSNCount(假設Table Name是dbo.test)
CREATE FUNCTION [dbo].[GetSNCount](@SN varchar(10))
RETURNS int
AS
BEGIN
Declare @SNCount int = 0
SELECT @SNCount=count(SN) from dbo.test where SN=@SN group by SN
set @SNCount = @SNCount + 1
-- Return the result of the function
RETURN @SNCount
END
2.Insert測試資料
insert test(sn,[count]) values('A',dbo.getSNCount('A'))
insert test(sn,[count]) values('B',dbo.getSNCount('B'))
insert test(sn,[count]) values('C',dbo.getSNCount('C'))
insert test(sn,[count]) values('B',dbo.getSNCount('B'))
insert test(sn,[count]) values('C',dbo.getSNCount('C'))
insert test(sn,[count]) values('C',dbo.getSNCount('C'))
3.結果如下
感謝您的詢問。 MS SQL Server 中如果不將該列設為主鍵,則無法直接基於另一列實作自增。 但是,您可以透過使用基於所需列遞增值的序列或觸發器來實現類似的功能。 至於rice purity test,它是一種有趣而輕鬆的方式來衡量一個人的純真或生活各個方面的經歷。 這是一個流行的網路測驗,涵蓋從個人行為到浪漫關係的廣泛主題。
Mbwhats.com is your prime source for MBWhatsApp, the popular modded version of WhatsApp. Stay updated on the latest MBWhatsApp APK releases, guides, tips and news. mbwhats.comhttps://mbwhats.com/
Download watch anime online. aniwatch.com.co is a fantastic anime streaming that allows users to watch their favorite anime shows on their mobile devices. With a vast collection of anime.
visit: http://aniwatch.com.co/
ChatGPT is an advanced AI chatbot engineered by OpenAI. It’s crafted to excel in a myriad of tasks, ranging from resolving your queries to rendering intricate information.
visit: https://chatgptdownload.me/
Enjoy the best doramas.
Doramasvip is the best free for all drama lovers: K-Drama, J-Drama, C-Drama, and many more.
Answer questions according to your level of knowledge in the Doramas in Spanish quiz.
visit: https://doramavip.com/
IGram on Download Instagram videos easily with IGram. This free online tool lets you save Instagram video posts directly to your device. visit our website https://igram.bar/
Pikashow APK offers HD streaming of entertainment. Includes TV shows and movies. Download the latest version for Android, PC or iOS. visit our website https://pikashowhd.net.in
This game provides an incredibly detailed driving environment, focusing on realistic vehicle behavior. In BeamNG.drive, players can experiment with different cars and terrains. The primary goal is to master the intricacies of driving and enjoy the realistic simulation of crashes and stunts.
Your mission in this game is to tick off as many boxes as you can. one million checkboxes offers a massive grid of checkboxes, and your objective is to mark as many as possible. The simplicity of the game hides a deeper challenge that requires concentration and patience.