带条件的 SQL Group By
场景:我需要为 ASP.Net 应用程序的审核员创建一份报告。我有一个程序,可以解析授权标签目录中 web.config 文件的 XML,并创建一个报告,提供哪些用户可以访问站点结构中的哪个文件夹。报告如下所示。
用户名、名字、姓氏、目录、角色、访问权限、 上次登录日期
问题:正如您从报告中看到的一些目录(中间其中包含 GISMO 的列)显示两次,同时允许和拒绝用户。我想知道是否有一种方法可以对结果进行分组,如果有一行允许目录,则不会显示拒绝的行,否则会显示拒绝的行。
或者,如果可以在 VB.net/C# 中操作,这也是一个选项。它返回那里并被输入到 Excel 电子表格中。
任何帮助表示赞赏。提前致谢。
编辑:我应该解释得更好。我仍然需要拒绝行来显示目录中是否不允许用户。但是,如果允许它们,则没有必要显示拒绝行。
Scenario: I need to create a report for the auditors for an ASP.Net application. I have a program that parses the XML of the web.config files in a directory for the authorization tag and creates a report providing which users have access to which folder in the site structure. The report is shown below.
UserName, Firstname, LastName, Directory, Roles, Access,
LastLoginDate
Problem: As you can see from the report some directories (the middle column with GISMO in it) show up twice, with both allow and deny for a user. I am wondering if there is a way to group the results in such a way that if there is a row that has allow for a directory then the deny's are not shown but otherwise they are.
Alternatively if this can be manipulated in VB.net/C# that is also an option. It comes back there and is pumped into an Excel spreadsheet.
Any help is appreciated. Thanks in advance.
Edit: I should have explained better. I still need the deny rows to show if the user isn't allowed in the directory. But if they are allowed then there is no point showing the deny rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这适用于 Oracle 数据库,因此它应该可以工作或让您接近 SQL Server,因为我知道 SQL Server
支持其主要组成部分,即 CASE 操作。
结果:
基本上,您使用数据透视表将多行聚合成一行来描述目录的属性。获得聚合行后,就可以轻松比较已声明的属性以连接要显示的行。
This works on an Oracle database, so it should work or get you close on SQL Server as I know SQL Server
supports the main component of this, the CASE operation.
Results:
Basically, you use a pivot table to aggregate the multiple rows into a single row describing the attributes for the directory. Once you have the aggregated row, it's easy to compare the attributes you've declared to join up the rows that you want to display.
如果您有 SQL Server 2005 或更高版本,则可以使用以下命令:
在分区子句中,输入使“组”唯一的任何内容。
参考:
http://msdn.microsoft.com/en-us/library/ms190766.aspx
http://msdn.microsoft.com/en-us/library/ms186734.aspx
If you've got SQL Server 2005 or newer, you can use this:
In the partition clause, put in whatever makes a "group" unique.
Reference:
http://msdn.microsoft.com/en-us/library/ms190766.aspx
http://msdn.microsoft.com/en-us/library/ms186734.aspx
像这样的东西应该可以工作,但这假设您的路径没有输入,例如 /directory/directory/、/directory/Directory/、directory/directory/default.aspx 等。您最好的选择是解析数据并删除重复项在您创建的 .NET 进程级别,因为该阶段的解析通常更容易。
Something like this should work but this assumes that your paths were not entered such as /directory/directory/, /directory/Directory/, directory/directory/default.aspx, etc. Your best bet would be to parse the data and remove duplicates at the .NET process level you've created, since parsing at that stage is usually easier.
根据您的评论,应删除此行,因此仅检查
(UserName, Directory)
组合:Based on your comments, this line should be removed, so only
(UserName, Directory)
combination is checked: