gpt4 book ai didi

ASP.NET SQL 查询

转载 作者:行者123 更新时间:2023-12-02 16:48:40 25 4
gpt4 key购买 nike

我从 SQL 查询中得到了这样的结果:

Month    Day  Customer     Item
------------------------------------------
January 1 John Pencil
January 1 Jack ---
January 1 Steve Stapler
January 2 John ---
January 2 Jack ---
January 2 Steve VisitingCard
January 3 John ---
January 3 Jack Marker
January 3 Steve ---
January 4 John ---
January 4 Jack ---
January 4 Steve ---
January 5 John Scrapbook
January 5 Jack ---
January 5 Steve ---
....
....
....
February 1 John ---
February 1 Jack ---
February 1 Steve Marker

我希望在 ASP.NET gridview 中表示如下:

                             January
Customer 1 2 3 4 5 6 7 8 9 10 11 ... 25 26 27 28 29 30 31
---------------------------------------------------------
John P - - - N - - - - -- -- -- -- -- -- -- -- --
Jack - - M - - - - - - -- -- -- -- -- -- -- -- --
Steve S V - - - - - - - -- -- -- -- -- -- -- -- --
February
Customer 1 2 3 4 5 6 7 8 9 10 11 ... 25 26 27 28
------------------------------------------------
John - - - - - - - - - -- -- -- -- -- --
Jack - - - - - - - - - -- -- -- -- -- --
Steve M - - - - - - - - -- -- -- -- -- --

如何在 SQL Server 2005 或 ASP.NET 2.0 中完成此操作?

请提供 PIVOT 的示例查询,因为它需要使用一些聚合函数。

最佳答案

您需要 Pivot命令。我不熟悉该命令的用法,但是geekswithblogs有一个关于如何使用它的很好的教程。

关于ASP.NET SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1027069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com