想在sql中创建一组记录。 [英] Want to create a group of records with in sql.

查看:77
本文介绍了想在sql中创建一组记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



需要帮助才能创建表结构:

我有这样的表结构:



Hi,
Need help to create a table structure:
I have a table structure like this :

i_d         I_d_value            Name      Message
1           11                   test1     test11 message
1           12                   test1     test12 message
1           13                   test1     test13 message
2           21                   test2     test21 message
2           22                   test2     test22 message
2           23                   test2     test23 message
2           24                   test2     test24 message
3           31                   test3     test31 message





我想创建一个管理结构的程序,如:





and i want to create procedure to manage the structure like:

i_d             I_d_value            Name      Message
1               11                   test1     test11 message
                12                   test1     test12 message
                13                   test1     test13 message
2               21                   test2     test21 message
                22                   test2     test22 message
                23                   test2     test23 message
                24                   test2     test24 message
3               31                   test3     test31 message





使用sql。

提前致谢。



我尝试了什么:



试图在gridview中处理但是无法成功。但是现在只想用sql。



using sql for this.
Thanks in advance.

What I have tried:

tried to handle in gridview but couldn't succeed. But now want to do with sql only.

推荐答案

你可以做到......但是它不能很好地利用SQL,那种事情要做得更好在表示语言中而不是在SQL中。

在SQL中它是这样的:

You can do it ... but it's not a good use of SQL, that kind of thing is much better done in a presentation language rather than in SQL.
In SQL its like this:
SELECT CASE WHEN I_D = LAG(I_D) OVER (ORDER BY I_D, I_D_Value) THEN NULL ELSE I_D END, 
       I_D_Value, [Name], [Message] FROM MyTable


这篇关于想在sql中创建一组记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆