查询SKU&的销售额总和日期的一部分 [英] Query to sum sales by SKU & portion of date

查看:65
本文介绍了查询SKU&的销售额总和日期的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个Access查询,该查询将报告SKU在给定月份的销售情况。数据表包含以下列:

展开 | 选择 | Wrap | 行号

解决方案

toddi76,
欢迎来到Bytes.com!


通常我们要求您展示您的作品;然而,对于一些更复杂的事情,或者当明显不是最简单的解决方案时(在本例中,红色鲱鱼比比皆是 - 在这种情况下, DatePart()! )...我已经在实验室中做了几十次这样的总结:

展开 | 选择 | Wrap | 行号


如果使用格式([ODate],''yyyymm'')对于你的 ORDER BY 子句,你会发现它更直接。


您必须在 GROUP BY 子句中使用相同的表达式,就像在<$ c $中一样c> SELECT 一个或它会抱怨。


NeoPa,

你在 GROUP BY ;但是,排序发生在 ORDER BY 中,因此有一些SQL-little手被拉到这里!


当您使用格式([ODate],''yyyymm'')代替 ORDER BY 时,我们会按照[ODate]的月份名称而不是数字日期排序进行按字母顺序排序 - 在我的实验室报告中尽早尝试 - 几乎足以让化学家疯狂......好像人们可以分辨出@; @;


因此,


要么

展开 | 选择 | 换行 | 行号

I am trying to write an Access query that will report sales by SKU for a given month. The data table has the following columns:

Expand|Select|Wrap|Line Numbers

解决方案

toddi76,
Welcome to Bytes.com!

Normally we ask that you show your work; however, with some of the more complex things, or when the obvious isn''t the easiest solution (red-herrings abound in Access - in this case, DatePart()!)... and I''ve done this type of summary dozens of times in the lab:

Expand|Select|Wrap|Line Numbers


If you use Format([ODate],''yyyymm'') for your ORDER BY clause you should find it a little more straightforward.

You must use the same expression in the GROUP BY clause as you do in the SELECT one or it''ll complain.


NeoPa,
You are absolutely correct in the GROUP BY; however, the sort is happening in the ORDER BY so there is a bit of SQL-slight of hand being pulled here!

When you use the Format([ODate],''yyyymm'') in place of the ORDER BY we then get the alphabetical sort by the Month name of [ODate] instead of the numerical Date sort - Tried this very early on for my lab reports - almost enough to drive a Chemist crazy... as if one could tell the difference @;@ ;

thus,

Either

Expand|Select|Wrap|Line Numbers


这篇关于查询SKU&amp;的销售额总和日期的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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