条件聚合引用表而不是手动输入(Conditional aggregation referencing table instead of manual entry)
我先前问了一个关于条件聚合的问题。 SQL Transform Crosstab Pivot和答案很棒! 但是,我需要对此进行扩展。
当时的解决方案是以下查询:
SELECT Item, [X] = MAX(CASE WHEN [Columns] = 'X' THEN Result END), [Y] = MAX(CASE WHEN [Columns] = 'Y' THEN Result END), [Z] = MAX(CASE WHEN [Columns] = 'Z' THEN Result END) FROM thisTable GROUP BY Item
问题:我现在有一个表格
TEST
其中W,X,Y,Z为行。 而不是向查询添加另一行([W] = MAX(CASE WHEN [Columns] = 'W' THEN Result END)
),可以重写上面的查询以引用值的表吗?原因是因为我预计不仅仅有W,X,Y,Z,并且希望将来避免在此查询中添加更多行。
I asked a question previously on conditional aggregation. SQL Transform Crosstab Pivot and the answer was great! However, I need to expand on this.
The solution at the time was the following query:
SELECT Item, [X] = MAX(CASE WHEN [Columns] = 'X' THEN Result END), [Y] = MAX(CASE WHEN [Columns] = 'Y' THEN Result END), [Z] = MAX(CASE WHEN [Columns] = 'Z' THEN Result END) FROM thisTable GROUP BY Item
Question: I now have a table
TEST
with W, X, Y, Z in rows. Instead of adding another line ([W] = MAX(CASE WHEN [Columns] = 'W' THEN Result END)
) to the query, can the query above be re-written to refer to the table for the values?The reason is because I anticipate that there will more than just W, X, Y, Z and want to avoid adding more lines to this query in the future.
原文:https://stackoverflow.com/questions/38109330
最满意答案
我不确定你是什么意思。 如果您想知道当前是否正在调试应用程序,可以检查
System.Diagnostics.Debugger.IsAttached
属性。 如果您想知道应用程序是否在调试模式下编译,那么您可以这样做:#if DEBUG const bool DebugMode = true; #else const bool DebugMode = false; #endif
此外,您可以使用ConditionalAttribute:
[System.Diagnostics.Conditional("DEBUG")] public void ThisMethodWillOnlyExecuteInDebugMode() { }
我强烈建议重新考虑这一点 - 根据我的经验,具有不同的发布和调试行为是将错误引入生产代码的绝佳方法。
I'm not sure what you mean. If you want to know if the application is currently being debugged, you can check the
System.Diagnostics.Debugger.IsAttached
property. If you want to know if the application is compiled in debug mode, then you can do this:#if DEBUG const bool DebugMode = true; #else const bool DebugMode = false; #endif
Also, you can use ConditionalAttribute:
[System.Diagnostics.Conditional("DEBUG")] public void ThisMethodWillOnlyExecuteInDebugMode() { }
I strongly suggest reconsidering that though - in my experience, having different release and debug behaviour is an excellent way to introduce bugs to your production code.
相关问答
更多-
如何在Visual Studio 2008中调试/运行经典的asp页面?(How do you Debug/Run classic asp pages in Visual Studio 2008?)[2022-10-27]
开发人员Web服务器(Cassini)仅支持ASP.NET和静态内容。 你需要一个在你的开发机器上运行的IIS实例。 Windows XP 在XP上,您需要修改默认网站,以便其主目录指向您的网站根文件夹或创建新的虚拟目录并将其配置为应用程序。 无论哪种情况,您都希望将应用程序隔离设置为“高” 直接用浏览器打你的网站,然后在VS 2008中使用Debug-> Attach to Process。 您需要附加名称为“DLLHOST.EXE”的进程。 将会有多于一个,但很可能只有其中一个在类型列中包含“脚本”一词 ... -
在Visual Studio 2008中调试HTTPS ASP.NET站点?(Debugging HTTPS ASP.NET site in Visual Studio 2008?)[2022-05-13]
是的,您可以通过单击项目上的“ Properties ”(在缓慢加载时耐心等待)将IIS设置为调试服务器,然后转到“ Web选项卡并选择“ Use IIS Web server而不是“ Use Visual Studio Development Server 。 - 编辑 更一般地说,为了回答这个问题,我通常只是在调试时禁用SSL。 我很少需要测试我是如何通过SSL处理事物的,并且根据我如何创建SSL链接,可以使用#if DEBUG简单地修改它。 Yes, you may set IIS as the de ... -
Visual Studio ASP.NET MVC项目:设置起始URL(Visual Studio ASP.NET MVC project: setting the start URL)[2023-07-26]
起始网址必须是完全限定的网址,并不是经常使用。 它是通过打开一个调用该服务的页面来测试Web服务,但不是应用程序本身的一部分。 如果您只是想在您的应用程序的某个页面上开始,那就是您想要的,请使用“特定页面”字段,然后输入相关URL。 这是项目启动选项的文档页面。 Start URL has to be a fully qualified URL and is not really used that often. It's meant for testing web services by opening ... -
在Visual Studio中运行Asp.NET项目时出现DataBase错误(DataBase Error while running Asp.NET project in Visual Studio)[2022-06-24]
我已经解决了这个问题。 安装visual studio 2015时,默认情况下未安装SQL database server 。 我再次使用database server修改了visual studio ,现在它正在工作。 谢谢大家。 I've solved this problem. The SQL database server was not installed by default when i installed the visual studio 2015. I again modified th ... -
我不确定你是什么意思。 如果您想知道当前是否正在调试应用程序,可以检查System.Diagnostics.Debugger.IsAttached属性。 如果您想知道应用程序是否在调试模式下编译,那么您可以这样做: #if DEBUG const bool DebugMode = true; #else const bool DebugMode = false; #endif 此外,您可以使用ConditionalAttribute: [System.Diagnostics.Condition ...
-
在Chrome中停止调试后,Visual Studio ASP.NET崩溃(Visual Studio ASP.NET crashes after Stop Debug in Chrome)[2022-08-07]
好吧,我没有设法找到问题,但我找到了解决方案。 因为它是一台新PC,所以它上面只有一点点膨胀软件。 我已经卸载了我不需要的东西,然后它神奇地工作了。 不再崩溃了。 我有一个华硕ROG G20AJ。 我不确切知道哪个臃肿软件导致了这个问题,但它是其中的一部分。 因此,如果您在华硕机器上遇到类似的问题,请尝试卸载一些未使用的软件。 它不是Visual Studio崩溃,它是IIS服务。 我真的认为这是一个非常奇怪的行为,因为崩溃只发生了,如果我执行上面的代码片段...无论如何,它现在有效! Ok, I didn ... -
这可能对你有用,我有一个类似的问题,因为我的解决方案中有几个web远程处理项目。 我所做的是为IIS中的每个设置虚拟目录,然后右键单击每个项目并选择属性。 在Web选项卡上,然后设置要在调试IIS时使用的服务器。 这会导致Visual Studio使用IIS的单个实例,而不是为每个项目打开十几个单独的Web开发服务器。 在调试时,请附加到w3wp.exe进程。 This might work for you, I have a similar issue since there are several we ...
-
Visual Studio 2010中的ASP.NET Web窗体站点在哪里?(where is ASP.NET Web Forms Site in Visual Studio 2010?)[2022-06-06]
您必须选择File => New => Project...而不是File => New => Web Site... 然后选择左侧的Visual C#/ Web模板组,然后在中间列中选择“ASP.NET Web应用程序”模板。 为项目命名,然后按“确定”按钮。 http://www.asp.net/web-forms/tutorials/tailspin-spyworks/tailspin-spyworks-part-1 You must choose File => New => Project... ... -
只有Internet Explorer可以执行此操作,因为它既是Microsoft产品。 由于Chrome无法直接访问Visual Studio,因此Chrome可以减少在PC上运行的IIS进程,这很奇怪。 如果您希望看到“停止调试行为”,则应使用Internet Explorer作为调试浏览器。 浏览器关闭时停止调试Visual Studio 2013 Visual Studio 2012 - IE关闭时停止调试 Only Internet Explorer can do this, as it's bo ...
-
使用Visual Studio 2008调试本地asp.net非常慢(debug local asp.net is very slow with Visual Studio 2008)[2023-07-15]
第一次编译代码确实需要一些时间 - 应用程序有多大? 后续加载应该花费更少的时间。 您是否尝试在Web应用程序的条目中设置断点以查看代码是否缓慢? First time compilation of your code does take some time - how big is the application? Subsequent loads should take less time. Have you tried setting breakpoints at the entry of your ...