MYsQL分组计数查询

时间:2012-05-11 06:20:41

标签: mysql

任何人请帮助我。

我有一个查询需要提取必须在流程上显示某个模型的详细信息的数据。

这是我的查询。

    select
x.Sequence as 'Sequence',
x.Process as 'Process',
x.pdt as 'Production Date',
x.mdl as 'Model',
count(x.bigbook) as 'Bigbook Count',
x.sb as 'Smallbook'
from
(
select distinct
'1' as 'Sequence',
'Cutting' as 'Process',
cut_pdt as 'PDT',
cut_shf as 'Shift',
cut_mdl as 'Mdl',
cut_bbn as 'Bigbook',
 count(cut_sbn) as 'SB'
from sum_cut_001 group by cut_bbn) x
group by x.mdl

它显示的结果是这样的。

---------|---------|-----------------|-------|----------------|------------------|
Sequence | Process | Production Date | Model | Big book Count | Small Book Count |
---------|---------|-----------------|-------|----------------|------------------|
1        | Cutting |    2012-01-30   |  GSX1 |     3          |        12        |

每个模型都有1个Bigbook,每个Bigbook有18个小书

因此,如果我有3个型号为GSX1的大书,那么输出应该是。

---------|---------|-----------------|-------|----------------|------------------|
Sequence | Process | Production Date | Model | Big book Count | Small Book Count |
---------|---------|-----------------|-------|----------------|------------------|
1        | Cutting |    2012-01-30   |  GSX1 |     3          |        54        |

请帮我解释如何正确查询。

提前感谢。

0 个答案:

没有答案