根据具有group by的另一个字段的条件,在不同字段中对一个字段求​​和 [英] Sum one field in different fields based on conditions on another field with group by

查看:98
本文介绍了根据具有group by的另一个字段的条件,在不同字段中对一个字段求​​和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我是mssql的初级用户,我一直陷入了一个我想要制作的报告中。

我有一个包含''PartName''字段的表,'' VoucherQuantity'',''VoucherType'',''VoucherDate''和''DLName''。我想得到''VoucherQuantity''的总和,我想根据''VoucherType''的不同值(例如可以是01,02,03或04)在不同的字段中得到结果,我想要结果按''PartName''和''DLName''分组。显然我想要这个总和在哪里''VoucherDate''在a和b之间。

我一直在尝试不同的查询,我尝试创建不同的视图来解决这个问题,但到目前为止我有zilch。如果有人能帮助我,我会非常感激!

Hi! I''m a beginner user of mssql and I''ve been stuck in a report that I''m trying to make.
I have a table with fields like ''PartName'', ''VoucherQuantity'', ''VoucherType'', ''VoucherDate'', and ''DLName''. I want to get the sum of ''VoucherQuantity'' and I want its results in different fields based on different values of ''VoucherType'' (which for example can be 01, 02, 03, or 04) and I want the result to be grouped by ''PartName'' AND ''DLName''. Obviously I want this sums WHERE ''VoucherDate'' IS BETWEEN a and b.
I''ve been trying different queries for a while and I have tried creating different views to solve this but so far I have got zilch. I''d really appreciate it a lot if anyone can help me!

推荐答案

我无法理解你的问题。一些示例数据和结果会有所帮助。
I have trouble understanding your question. Some sample data and results would help.


感谢您回答亲爱的兔子。


我已将数据集和结果集附加到excel文件中。

我希望那些表格足够清晰。对于每个PartName-DlName组合,我想得到一个字段中vchtype = 01的数量和另一个字段中vchtype = 02的数量之和。





Thanks for answering dear Rabbit.

I have attached the data set and result set in an excel file.
I hope those tables are clear enough. For every PartName-DlName combination, I want to get the sum of the quantities of vchtype=01 in one field and sum of the quantities of vchtype=02 in another field.
附加文件
mssql.xlsx (8.7 KB,291 views)
Attached Files
mssql.xlsx (8.7 KB, 291 views)


我不打开那些我不知道的人的附件。请在线程本身发布一些示例数据和结果。
I don''t open attachments from people I don''t know. Please post some sample data and results in the thread itself.


这篇关于根据具有group by的另一个字段的条件,在不同字段中对一个字段求​​和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆