讲解一下这个代码 ```sum(case when coalesce(ad_source,'') not in ('ADX','联运DSP') and (cast(coalesce(trim(clicktype),'0') as bigint) & 8 ) <> '8' then price_cost else 0 end) expect_acc_cost,```

时间: 2023-12-30 13:03:44 浏览: 24
这段代码主要是一个SQL语句中的一个聚合函数SUM中的CASE表达式。 CASE表达式的语法如下: ``` CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ... ELSE result END ``` 它的作用是根据条件进行判断并返回对应的结果。在这段代码中,CASE表达式中的条件是: ``` coalesce(ad_source,'') not in ('ADX','联运DSP') and (cast(coalesce(trim(clicktype),'0') as bigint) & 8 ) <> '8' ``` 这个条件包括两个部分: 1. coalesce(ad_source,'') not in ('ADX','联运DSP'):这个部分判断ad_source是否在指定的值列表中,如果不在则返回true,否则返回false。coalesce函数是用来判断ad_source是否为null,如果为null则返回空字符串。 2. (cast(coalesce(trim(clicktype),'0') as bigint) & 8 ) <> '8':这个部分将clicktype转换为bigint类型,并与8进行按位与运算(&操作),判断结果是否等于8,如果不等于则返回true,否则返回false。trim函数是用来去掉clicktype两端的空格。 根据以上条件,如果满足条件,则返回price_cost,否则返回0。整个CASE表达式的作用是,将不满足条件的price_cost设为0,而满足条件的price_cost保持原值。 接下来,这个CASE表达式被用在了SUM函数中,表示对所有满足条件的price_cost进行求和,得到的结果存储在一个名为expect_acc_cost的变量中。

相关推荐

select lot_hs.lot_id as lot_id,lot_type,lot_hs.mainpd_id, created_time,COMPLETE_TIME, value(bank.banktime,0) as banktime , round ( ( 1.00*(days(COMPLETE_TIME)-days(created_time)) + (hour(COMPLETE_TIME)-hour(created_time))*1.00/24 + (minute(COMPLETE_TIME)-minute(created_time))*1.00/24/60 + (second(COMPLETE_TIME)-second(created_time))1.00/24/60/60) - value(bank.banktime,0),3) as use_days, customer_id, coalesce(cc.cust_id_define,lot_hs.customer_id) as cust_id2, cc.cycletime_target as ct_target, date,layer, round(count() over(partition by coalesce(cc.cust_id_define,lot_hs.customer_id),cc.cycletime_target)*0.9,0) cnt, row_number() over(partition by coalesce(cc.cust_id_define,lot_hs.customer_id),cc.cycletime_target order by ( ( days(COMPLETE_TIME)-days(created_time) + (hour(COMPLETE_TIME)-hour(created_time))*1.00/24 + (minute(COMPLETE_TIME)-minute(created_time))*1.00/24/60 + (second(COMPLETE_TIME)-second(created_time))*1.00/24/60/60) - value(bank.banktime,0))/layer) id From (select date(a.claim_time) as date, a.lot_id, a.lot_type,a.mainpd_id,a.prodspec_id,a.custprod_id, case when(date(b.created_time) <= '2009-01-05') then b.created_time + 21 days else b.created_time end as created_time, CASE WHEN A.CUST_id in ('MCA','NPA','SET') THEN a.COMPLETE_TIME ELSE a.COMPLETE_TIME END COMPLETE_TIME, a.cust_id as customer_id, a.ope_category, c.layer From f3rpt.F3_TB_DAILY_FABOUT a, f3rpt.fvlot b, (select mainpd_id, sum(masks)layer from f3rpt.ASMCRPT_VW_MAINPD_MASKS_ALL group by mainpd_id) as c, (select * from (select lot_id, max(claim_time)claim_time, count(case when(ope_category='Ship')then lot_id else null end) as LS, count(case when(ope_category='Unship') then lot_id else null end) as LUS from f3rpt.F3_TB_DAILY_FABOUT where substr(lot_id,1,2) not in('CA','CW','ES','E0','EM') and lot_type = 'Production' AND LOT_ID NOT LIKE 'H%' and substr(lot_id,7,4)='.00F' and ope_category in ('Ship','Unship') and year(claim_time) = year(current date - 1 days) and month(claim_time) = month(current date - 1 days) group by lot_id) as a where LS - LUS > 0 ) as lot Where a.lot_id = b.lot_id and b.mainpd_id = c.mainpd_id and a.lot_id = lot.LOT_ID and a.claim_time = lot.claim_time and a.ope_category = 'Ship' and a.cust_id in ('SM','BOE','GSC','NPA','GTA') ) as lot_hs left outer join (select lot_id,max(bankin_time) banktime from f3rpt.asmc_dpm where bankin_time>0 group by lot_id) bank on (lot_hs.lot_id = bank.lot_id) left join f3cim.f3cim_cfg_cust_rule cc on case when lot_hs.customer_id='WXM' THEN 'WII'||SUBSTR(lot_hs.mainpd_id,6,1) else lot_hs.customer_id end = cc.cust_id and locate(cc.mainpd_id,lot_hs.mainpd_id)>0 and locate(cc.prodspec_id,lot_hs.prodspec_id)>0 and locate(cc.custprod_id_45,substr(lot_hs.custprod_id,3,3))>0 where lot_hs.ope_category = 'Ship' ;以上sql如何优化

最新推荐

recommend-type

MySql COALESCE函数使用方法代码案例

主要介绍了MySql COALESCE函数使用方法代码案例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
recommend-type

mysql中替代null的IFNULL()与COALESCE()函数详解

主要给大家介绍了关于mysql中替代null的IFNULL()与COALESCE()函数的相关资料,文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看看吧。
recommend-type

华为OD机试D卷 - 用连续自然数之和来表达整数 - 免费看解析和代码.html

私信博主免费获取真题解析以及代码
recommend-type

Screenshot_2024-05-10-20-21-01-857_com.chaoxing.mobile.jpg

Screenshot_2024-05-10-20-21-01-857_com.chaoxing.mobile.jpg
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

spring添加xml配置文件

1. 创建一个新的Spring配置文件,例如"applicationContext.xml"。 2. 在文件头部添加XML命名空间和schema定义,如下所示: ``` <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依