MySQL select 用于全局销售报告

标签 mysql sql reportviewer

我在.Net中有一个带有Reportviewer的网络应用程序,我使用reportviewer MySql查询的源数据,我需要制作一份全局销售报告,我有这个表销售:

|IdSale|数量|日期|价格|等等...

(我的问题的重要部分是下一个,我需要计算具有相同编号的每一行的价格总和。为什么?编号数据字段是收据或账单,因此我可以为该编号进行一次销售收据/账单编号 6,我售出 2 件商品:

|IdSale|Number| Date |Price|

|  1   |  6   |20/08 |  50€|
|  2   |  6   |20/08 |  10€|
----------------------------

所以我需要得到该总和但是,与其他数字我的意思是我可以用这个查询做到这一点:

Select distinct sales.Number, sales.Date, SUM(sales.Price) as 'Importe', 
from sales where number = 6;*

然后返回

|Number|Date|Importe(price)|
|  6   |20/8|    100€      | 

没关系,但是当我有这个

|IdSale|Number| Date |Price|
|  1   |  6   |20/08 |  50€|
|  2   |  6   |20/08 |  10€|
|  3   |  7   |20/08 |  30€|
|  4   |  8   |20/08 |  20€|
----------------------------

我需要得到这个输出

|Number|Date|Importe(price)|
|  6   |20/8|    100€      |
|  7   |20/8|    30€       | 
|  8   |20/8|    20€       | 

但我唯一做的就是使用这个查询

Select distinct sales.Number, sales.Date, SUM(sales.Price) as 'Importe', 
from sales where number >= 0;


|Number|Date|Importe(price|
|  2   |20/8| 150€        |

所以我得到了所有的总和,但我只需要具有相同数字的每行的总和,我可以这样做吗?

最佳答案

您只是在寻找分组依据吗?

Select s.Number, s.Date, SUM(s.Price) as Importe, 
from sales s
group by s.Number, s.Date;

关于MySQL select 用于全局销售报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32115950/

相关文章:

sql - 更有效地旋转行

mysql - 从数据表中获取前四个值。然后根据条件交换

php - 无法从多个 html 复选框访问值

php - 使用 PHP 进行正确且方便的错误处理和日志记录

mysql - 如何从 MySQL 中的查询中获取所有数据?

wpf - WinForms ReportViewer 挂起应用程序 WPF

reporting-services - ReportViewer 控件末尾的 SSRS 额外空白页不在 PDF 中

c# - 在 rdlc 报告中创建嵌套的 tablix

php - MySQL:获取表的所有以名称 "ctr_"和值 1 开头的列

php - 大量的小 SQL 语句会显着减慢我的网站速度吗