去百度上 查过了 是字段的类型转换的时候 出错了 然后百度上的案例没看懂 有大佬指点一下嘛 SQL server 数据库 执行sql 如下: --库存数据的处理 以及与基础信息关联 with AA AS (select --过滤库存数据 AB AS (SELECT * from kucun where ck_name in ('芭欧成品天猫仓','芭欧outlets仓','芭欧成品唯品会仓','芭欧成品云集仓','芭欧成品好衣库仓','芭欧成品爱库存仓','芭欧拼多多仓', AC AS (SELECT *,(case CK_Name when '芭欧成品天猫仓' then 'B天猫' --调整库存数据字段内容 AD AS (SELECT *,(case CK_Name_II when 'B天猫' then 'B仓' --过滤掉特殊商品编码 AE AS (SELECT * FROM AD WHERE CODE NOT LIKE 'WJ%' AND CODE NOT LIKE 'YD%' AND CODE NOT LIKE 'FCD%' AND CODE NOT LIKE 'KF%' AND CODE NOT LIKE 'ST%' AND CODE NOT LIKE 'TZ%' ), --将库存数据与基础数据 放在一起 AF AS (select distinct --顶层码数据为空时 加入唯品货号得数据 AG AS (SELECT *,(CASE WHEN DESIGNKCODE IS NULL THEN ExtStr1 ELSE DESIGNKCODE END) AS DESIGNKCODE_I FROM AF), --大类数据为空时 加入细类得数据 AH AS (SELECT *,(CASE WHEN BIG_TYPE IS NULL THEN TYPE ELSE BIG_TYPE END) AS BIG_TYPE_I FROM AG), --合并单元格数据,做唯一值 AL AS (select DESIGNKCODE_I AS DESIGNKCODE, --销量数据的处理 以及与基础信息的关联 CA AS (select --对销量数据表的店铺内容进行过滤 CC as (select * from JinQiXiaoLiang_I where DianPu in ('芭欧服饰旗舰店','芭欧outlets店','薇薇卡旗舰店','芭欧唯品会','薇薇卡唯品会','COCO唯品会','芭欧云集POP店','芭欧云集B2B平台', --将销量数据得两个表合并 CD as (select RiQi,DianPu,ExtStr1,skucode,XiaoLiang,Color,Size from CC CE as (SELECT *,(case DianPu when '芭欧服饰旗舰店' then 'B天猫' --过滤掉一些唯品编码 CF AS (SELECT * FROM CE WHERE ExtStr1 NOT LIKE 'WJ%' AND ExtStr1 NOT LIKE 'YD%' AND ExtStr1 NOT LIKE 'FCD%' AND ExtStr1 NOT LIKE 'KF%' AND ExtStr1 NOT LIKE 'ST%' AND ExtStr1 NOT LIKE 'TZ%'), CG AS (SELECT A.DESIGNKCODE,A.ExtStr1,A.CODE,F.SKUCODE,A.PP,A.TYPE,A.BIG_TYPE,A.COST,F.Color,F.Size,F.RIQI,F.XIAOLIANG,F.DIANPU_II --找出 没有关联上库存的基本信息的销量的数据 CH AS (select * FROM CF WHERE EXTSTR1 NOT IN (SELECT EXTSTR1 FROM CA)), --给 CH 的数据 关联基本信息 CI AS (select --关联大类 CJ AS (select --与销量的主表数据放到一起 CK AS (select * from CG --顶层码数据为空时 加入唯品货号得数据 CL AS (SELECT *,(CASE WHEN DESIGNKCODE IS NULL THEN ExtStr1 ELSE DESIGNKCODE END) AS DESIGNKCODE_I FROM CK), --大类数据为空时 加入细类得数据 CM AS (SELECT *,(CASE WHEN BIG_TYPE IS NULL THEN TYPE ELSE BIG_TYPE END) AS BIG_TYPE_I FROM CL), --过滤掉一些商品编码 CN AS (SELECT * FROM CM WHERE CODE not in (select CODE from CI where PP = '芭欧' and CODE like 'A%')), --做唯一值 CO AS (select TOP 100 PERCENT * , concat(designkcode_I,Color,size) as 'WeiYiZhi'from CN WHERE XIAOLIANG IS NOT NULL ORDER BY RIQI DESC), --求出近七天销量和 CP AS (select DISTINCT WEIYIZHI,SKUCODE,EXTSTR1,DIANPU_II,sum(xiaoliang)AS XIAOLIANG7 from CO where RIQI > GETDATE() - 7 group by WEIYIZHI,SKUCODE,EXTSTR1,DIANPU_II), --将近七天销量和得数据 与主表数据关联 CQ AS (SELECT DISTINCT --求出近三十天销量和 CR AS (select DISTINCT WEIYIZHI,SKUCODE,EXTSTR1,DIANPU_II,sum(xiaoliang)AS XIAOLIANG30 from CO where RIQI > GETDATE() - 30 group by WEIYIZHI,SKUCODE,EXTSTR1,DIANPU_II), --将近三十天销量和得数据 与主表数据关联 CS AS (SELECT DISTINCT --将销量数据里有 但是库存数据里没有的数据 放入库存数据表中;将库存数据里有 但是销量数据表里没有的数据 放入销量数据表中 EA AS (SELECT * FROM AL WHERE EXTSTR1 NOT IN (select EXTSTR1 FROM CS WHERE EXTSTR1 IS NOT NULL)), --在销量表里 不在库存表的唯品货号数 297 EB AS (SELECT * FROM CS WHERE EXTSTR1 NOT IN (select DISTINCT EXTSTR1 FROM AL WHERE EXTSTR1 IS NOT NULL)), --将库存数据里有 但是销量数据表里没有的数据 放入销量数据表中 9455 4826 EC AS (SELECT DESIGNKCODE,EXTSTR1,CODE,SKUCODE,PP,TYPE,BIG_TYPE,COST,COLOR,SIZE,WEIYIZHI,DIANPU_II,XIAOLIANG7,DIANPU_III,XIAOLIANG30 FROM CS --将销量数据里有 但是库存数据里没有的数据 放入库存数据表中 13870 623 SELECT DESIGNKCODE,YEARS,EXTSTR1,CODE,SKUCODE,PP,TYPE,BIG_TYPE,COLOR,SIZE,CK_NAME_II,DIAOBOZHANYONG,KEXIAO,ZAITU,CK_NAME_III,WEIYIZHI FROM AL |
最佳回答 |
||||
1
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|
|||
0
|
|