select substr(cust.customertype, 1, 1) ty,
cigOrder.item_id itemId,
sum(qty_ord) ord, --销量
count(distinct seller_id) custNum, --上柜客户数
sum(qty_ord * pri3 - qty_ord * unit_cost) profit
from (select * from tb_customer_info where status = '有效') cust,
(select branch_id,
manager_id,
qty_ord,
seller_id,
pri3,
unit_cost,
item_id
from tb_cig_order
where 1 = 1
and (item_id = '6901028180504' or
item_id in
('6901028207881', '6901028149242', '6901028143080'))
where 1 = 1
and cigOrder.manager_id = '103701010009'
and cigOrder.manager_id = cust.manager_id
group by cigOrder.item_id, substr(cust.customertype, 1, 1)
上面是我的sql语句,出现的问题是计算销量啥的都正确,但是我标注的那个上柜客户数确有问题,问题是它只按照item_id分组的
结果进行了统计,而没有按照item_id和substr(cust.customertype, 1, 1)一起分组后的结果统计。这是为什么?
查询的结果是
B 6901028143080 17388 31 539028
C 6901028143080 6118 31 189658
Q 6901028143080 17388 31 539028
Y 6901028143080 2898 31 89838
Z 6901028143080 20930 31 648830
B 6901028149242 220428 197 4959630
C 6901028149242 77558 197 1745055
Q 6901028149242 220428 197 4959630
Y 6901028149242 36738 197 826605
Z 6901028149242 265330 197 5969925
B 6901028180504 52380 143 1414260
C 6901028180504 18430 143 497610
Q 6901028180504 52380 143 1414260
Y 6901028180504 8730 143 235710
Z 6901028180504 63050 143 1702350
B 6901028207881 145962 183 3940974
C 6901028207881 51357 183 1386639
Q 6901028207881 145962 183 3940974
Y 6901028207881 24327 183 656829
Z 6901028207881 175695 183 4743765
第四列的结果是不正确的值应该都不同的
请帮助
cigOrder.item_id itemId,
sum(qty_ord) ord, --销量
count(distinct seller_id) custNum, --上柜客户数
sum(qty_ord * pri3 - qty_ord * unit_cost) profit
from (select * from tb_customer_info where status = '有效') cust,
(select branch_id,
manager_id,
qty_ord,
seller_id,
pri3,
unit_cost,
item_id
from tb_cig_order
where 1 = 1
and (item_id = '6901028180504' or
item_id in
('6901028207881', '6901028149242', '6901028143080'))
where 1 = 1
and cigOrder.manager_id = '103701010009'
and cigOrder.manager_id = cust.manager_id
group by cigOrder.item_id, substr(cust.customertype, 1, 1)
上面是我的sql语句,出现的问题是计算销量啥的都正确,但是我标注的那个上柜客户数确有问题,问题是它只按照item_id分组的
结果进行了统计,而没有按照item_id和substr(cust.customertype, 1, 1)一起分组后的结果统计。这是为什么?
查询的结果是
B 6901028143080 17388 31 539028
C 6901028143080 6118 31 189658
Q 6901028143080 17388 31 539028
Y 6901028143080 2898 31 89838
Z 6901028143080 20930 31 648830
B 6901028149242 220428 197 4959630
C 6901028149242 77558 197 1745055
Q 6901028149242 220428 197 4959630
Y 6901028149242 36738 197 826605
Z 6901028149242 265330 197 5969925
B 6901028180504 52380 143 1414260
C 6901028180504 18430 143 497610
Q 6901028180504 52380 143 1414260
Y 6901028180504 8730 143 235710
Z 6901028180504 63050 143 1702350
B 6901028207881 145962 183 3940974
C 6901028207881 51357 183 1386639
Q 6901028207881 145962 183 3940974
Y 6901028207881 24327 183 656829
Z 6901028207881 175695 183 4743765
第四列的结果是不正确的值应该都不同的
请帮助
解决方案 »
- Linux 环境下登录oracle失败,提示ORA-12541: TNS: 无监听程序
- Oracle9i缺少服务
- oracle sql developer如何连接DB2和MS SQL?
- 请教1个关于数据库迁移的问题!
- 关于自身连接的问题?这样为什么结果不一样?
- 用DriverManager和DataSource取得一个OracleConnection有什么不同嘛?
- 存储过程编译时的pls-00103错误
- 求一条SQL语句,在线等,结贴就给分!
- 请问:数据文件脱机,如何恢复?
- expdp hang起了。求助!
- 如何根据流水帐记录使用一条SQL产生某月财务期初、期未库存表?
- 关于oracle 的trigger?
结果并没有重复
请看看:
B 6901028143080 31
C 6901028143080 31
Q 6901028143080 31
C 6901028143080 6118 3 189658 也就是说第四列的值应该不同,而现在统计好像只按照item_id分组后的计算的count值,没有按照item_id和substr(cust.customertype, 1, 1)
分组后计算count(seller_id)
不知道说没说清楚。
CIGORDER.ITEM_ID ITEMID,
SUM(QTY_ORD) ORD, --销量
COUNT(DISTINCT SELLER_ID) CUSTNUM, --上柜客户数
SUM(QTY_ORD * PRI3 - QTY_ORD * UNIT_COST) PROFIT
FROM (SELECT * FROM TB_CUSTOMER_INFO WHERE STATUS = '有效') CUST,
(SELECT BRANCH_ID,
MANAGER_ID,
QTY_ORD,
SELLER_ID,
PRI3,
UNIT_COST,
ITEM_ID
FROM TB_CIG_ORDER
WHERE 1 = 1
AND (ITEM_ID = '6901028180504' OR
ITEM_ID IN
('6901028207881', '6901028149242', '6901028143080')))
WHERE 1 = 1
AND CIGORDER.MANAGER_ID = '103701010009'
AND CIGORDER.MANAGER_ID = CUST.MANAGER_ID
GROUP BY CIGORDER.ITEM_ID, SUBSTR(CUST.CUSTOMERTYPE, 1, 1)