按收入对交易进行排序,这是MySQL中订单表行的总和(Sorting deals by their revenue, which is sum of orders table rows in MySQL)
好吧,我一直质疑这一点,但直到今天才真正需要它。
通常情况下,我会抓住所有交易,分别查看所有交易,并从与此交易相关的所有订单中找到SUM(金额)。 (PHP)
然后我会做一个简单的uasort()工作正常。
但现在我需要使用sql查询来完成所有操作。
这是我尝试过的:
SELECT deals.ID, SUM(orders.amount) AS revenue FROM deals JOIN orders ON (orders.deal_id = deals.id) ORDER BY revenue DESC
现在这给了我一行,带有“随机”交易ID,收入数字更大。
我怀疑收入中的这个数字是所有金额列的总和,而不是这个特定的交易ID。
我想要的是每个交易ID的一行,并且在列收入中有正确的数字,所有行都排序DESC。
这怎么办? 要对交易进行排序,请从其收入(自定义列)中进行排序 - 这是相应交易ID的行中所有金额列的总和。
Okay I always have questioned this, but never really needed it until today.
Normally, I would grab all deals, go through them each and find the SUM(amount) from all the orders related to this deal. (PHP)
Then I would do a simple uasort() which works fine.
But now I need to do it all with a sql query.
This is what I have tried:
SELECT deals.ID, SUM(orders.amount) AS revenue FROM deals JOIN orders ON (orders.deal_id = deals.id) ORDER BY revenue DESC
Now this gives me one row, with a 'random' deal ID, and a bigger number in revenue.
I suspect this number in revenue is the SUM of ALL the amount columns, and not for this particular deal ID.
What I would like is a row for each deal ID, and with the right number in the column revenue, all the rows sorted DESC.
How would this be done? To sort the deals, out from their revenue (custom column) - which is the sum of all the amount columns from the rows for the respective deal id.
原文:https://stackoverflow.com/questions/13435139
最满意答案
好的,我得到了解决方案! ...我在这里写,也许可以提供帮助。
在我的wp-config.php中 ,
我添加了这些行:
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';
在代码中的所有内容之前。
以前,我粘贴上面的代码来修复文件末尾的admin无限自动循环。
希望能帮助到你!!!
Ok, I got the solution! ... I write here, maybe can be helpful.
In my wp-config.php,
I added these lines:
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on';
BEFORE everything in the code.
Previously, I pasted the code above to fix admin infinite auto-loop at the end of file.
Hope it helps!!!
相关问答
更多-
为了记录,这是我如何设置apache作为具有基本身份验证的转发代理: 打开http.conf 取消注释以下LoadModule指令以启用代理功能 LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so 将以下指令添加到http.conf以启用身份验证 ProxyRequests On ProxyVia On
Order deny,al ... -
第一个,是的。 来自Sun的自定义代码通过JNI调用SSPI将仅对Windows上的NTLM做出反应。 第二,没有。 这是MS的限制。 除非您编写SSPI JGSS桥接器。 您可以将Authenticator换成自定义的。 First one, yes. Custom code from Sun which calls SSPI via JNI will react on NTLM on Windows only. Second, no. This is a MS resctriction. Unless ...
-
代理传递背后的wordpress - 管理员身份验证不起作用(wordpress behind proxy pass - admin authentication does't work)[2021-09-28]
好的,我得到了解决方案! ...我在这里写,也许可以提供帮助。 在我的wp-config.php中 , 我添加了这些行: if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) $_SERVER['HTTPS']='on'; 在代码中的所有内容之前。 以前,我粘贴上面的代码来修复文件末尾的admin无限自动循环。 希望能帮助到你!!! Ok, I got the solution! ... I write here, ma ... -
我已经尝试过在Olaf Heimburger的文章中解释的内容: 在JPA中使用Oracle代理身份验证(EclipseLink-Style) 。 但我不确定为什么这个解决方案对我不起作用。 我正在使用Oracle Dababase 10g,JBoss 7.1.1和EclipseLink 2.5.1提供程序,我选择的应用程序体系结构是一个带有EJB注入和容器管理实体管理器(事务范围)的JSF 2.0 Web应用程序。 因为我花了很多时间寻找Oracle代理身份验证解决方案,所以我将解释我所做的事情。 我在我 ...
-
这是相关文件--django / contrib / admin / sites.py 。 特别是,请查看第170行的admin_view装饰器(这是调用login位置)和第211行的wrap装饰器,后者应用于第217行的urlpatterns每个视图。(这与login_required的方式类似)来自django.contrib.auth装饰工程)。 基本上,每个视图都包含在一个装饰器中,用于检查用户是否可以访问管理站点(第147行, request.user.is_active and request. ...
-
我在CouchDB问题跟踪器中发现代理验证在2.0.0版中被破坏。 无论是该文件还是文档都不会更新以表明它只适用于群集或其他内容。 我改回1.6.1版,一切正常。 我必须说,代理验证如何工作的文档非常差。 它是如何工作的,你需要你的第三方认证服务器拥有“[couch_httpd_auth]秘密”,当客户端认证时,你需要通过组合用户名和密码来生成一个HMAC-SHA1令牌。 然后,在您从客户端到CouchDB服务器的任何http请求中,如果包含所有标头: X-Auth-CouchDB-Roles X-Auth ...
-
当需要HTTPS和代理身份验证时,Python机械化不起作用(Python mechanize doesn't work when HTTPS and Proxy Authentication required)[2023-11-08]
我不建议你使用Mechanize,它已经过时了。 看看它会让你的生活变得更轻松的要求。 将代理与请求一起使用就是这样: import requests proxies = { "http": "10.10.1.10:3128", "https": "10.10.1.10:1080", } requests.get("http://example.org", proxies=proxies) I don't recommend you to use Mechanize, it's outdate ... -
你为什么不尝试SSH端口转发? IE浏览器。 您连接到主机服务器,并告诉它将本地端口转发到SQL Server。 然后使用localhost:port在本地计算机上连接,您的连接将通过主机服务器通过ssh进行隧道连接。 如果您的本地计算机是Windows计算机,则只需下载PuTTY并按照这些说明设置端口转发: http : //www.cs.uu.nl/technical/services/ssh/putty/puttyfw.html 。 问题当然是你的Windows凭据是否会被传递,但理论上这应该是有用的 ...
-
解决了它: 我在cookie路径配置中犯了一个小错误。 它一定要是: ProxyPassReverseCookiePath http://192.168.101.11/blog http://blog.domain.com Solved it: I made a slight mistake in the cookie path configuration. It has to be: ProxyPassReverseCookiePath http://192.168.101.11/blog http:/ ...
-
通过代理连接与身份验证后SocketTimeoutException(SocketTimeoutException after connecting via proxy with authentication)[2023-05-22]
它发生的警告与例外无关。 抛出异常是因为webservice不支持分块消息。 简单地添加这个解决了这个问题: options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,Boolean.FALSE); 警告本身很奇怪,但有一种方法可以将其删除,只需添加任何登录名和密码即可。 目的地不需要,但警告消失。 It happens that the warning has nothing to do with the excep ...