首页 \ 问答 \ 按收入对交易进行排序,这是MySQL中订单表行的总和(Sorting deals by their revenue, which is sum of orders table rows in MySQL)

按收入对交易进行排序,这是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
更新时间:2021-04-07 18:04

最满意答案

好的,我得到了解决方案! ...我在这里写,也许可以提供帮助。

在我的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 ...
  • 好的,我得到了解决方案! ...我在这里写,也许可以提供帮助。 在我的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 ...
  • 我不建议你使用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:/ ...
  • 它发生的警告与例外无关。 抛出异常是因为webservice不支持分块消息。 简单地添加这个解决了这个问题: options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,Boolean.FALSE); 警告本身很奇怪,但有一种方法可以将其删除,只需添加任何登录名和密码即可。 目的地不需要,但警告消失。 It happens that the warning has nothing to do with the excep ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)