首页 > 数据库 >mysql 部分计算调拨逻辑

mysql 部分计算调拨逻辑

时间:2022-11-03 11:55:28浏览次数:40  
标签:-% 逻辑 调拨 仓库 t4 sp mysql date day

select t4.sp码,
t4.zaitu as '在途',
t4.仓库名称 AS '中心仓',
t4.标品名称,
t4.库存成本,
t4.货主,
t4.分类名称,
t4.一级分类名称,
t4.库存数量 as '中心仓库存',
t4.前置仓,
t4.城市,
IFNULL(t1.有库存天数, 0) AS '有库存天数',
IFNULL(t2.销量, 0) AS '销量',
IFNULL(t2.销售天数, 0) AS '销售天数',
IFNULL(t_14.近12日销量, 0) AS '近12日销量'
from(
select t.sp码, ifnull((xtw.库存数量+ xtw.wms在途数量+ xtw.wms验收中数量), 0) as zaitu, t.仓库名称, t.标品名称, t.库存成本, t.货主, t.分类名称, t.一级分类名称, t.库存数量, xtwr.前置仓, xtwr.城市
from(
SELECT 仓库名称, 标品名称, sp码, 货主, 分类名称, 一级分类名称, 库存数量, 库存成本
FROM xtw_stock xtws
where 仓库名称 like "%中心仓%" and 库存数量> 0) t
left JOIN xtw_relation xtwr
on t.仓库名称= xtwr.配属中心仓
left join xtw_stock xtw on xtwr.前置仓= xtw.仓库名称
and t.sp码= xtw.sp码 and t.货主= xtw.货主) t4

-- 库存情况
left join(
SELECT 仓库, sp_code, COUNT(DISTINCT pt(day)) as '有库存天数'
FROM stock
where date_format(pt(day), '%Y-%m-%d')> date_sub(curdate(), interval 30 day)
AND date_format(pt(day), '%Y-%m-%d')< date_sub(curdate(), interval 0 day)
GROUP BY 仓库, sp_code) t1
on t1.仓库= t4.前置仓and t1.sp_code= t4.sp码

-- 销售情况
left join
(
SELECT 仓库, sp_code, SUM(货值) AS '销售货值', sum(数量) AS '销量', count(DISTINCT pt(day)) as '销售天数'
FROM SALE
where date_format(pt(day), '%Y-%m-%d')>= date_sub(curdate(), interval 30 day)
AND date_format(pt(day), '%Y-%m-%d')< date_sub(curdate(), interval 0 day)
GROUP BY 仓库, sp_code) t2
on t2.仓库= t4.前置仓and t2.sp_code= t4.sp码

-- 近14日销量
LEFT JOIN
(
SELECT 仓库, sp_code, sum(数量) AS '近12日销量'
FROM SALE
where date_format(pt(day), '%Y-%m-%d')>= date_sub(curdate(), interval 12 day)
AND date_format(pt(day), '%Y-%m-%d')< date_sub(curdate(), interval 0 day)
group by 仓库, sp_code) t_14
on t_14.仓库= t4.前置仓and t_14 .sp_code= t4.sp码

标签:-%,逻辑,调拨,仓库,t4,sp,mysql,date,day
From: https://www.cnblogs.com/ivan09/p/16853973.html

相关文章

  • MySQL生成连续的数
    背景MySQL版本5.7,需要生成连续的日期,只通过select,而不走自定义函数或存储过程思路只需要生成连续的数字,然后通过日期时间函数操作即可脚本SELECT DATE_ADD......
  • MySQL 忘记密码
    关闭正在运行的mysql服务以安全模式启动mysqlmysqld--shared-memory--skip-grant-tables--console使用另一个命令行连接mysql数据库。无需输入密码,直接回车跳过......
  • 查看mysql资源使用情况
    usesysselectevent_name,current_allocfromsys.memory_global_by_current_byteslimit10;selecthost,current_allocatedfrommemory_by_host_by_current_byte......
  • 软件设计__ 数据库逻辑结构设计
    难度:★★☆案例引入YourTour系统(旅游线路预定系统)YourTour是一个为旅行社和其目标顾客提供服务的系统。它能够将多个景点组成一条旅游线路,而且能够为所有参加线路的游......
  • MySQL如何保证数据一致性
    如何保证一致性数据库通过原子性(A)、隔离性(I)、持久性(D)来保证一致性(C)。其中一致性是目的,原子性、隔离性、持久性是手段。因此数据库必须实现AID三大特性才有可能实现一致性......
  • mysql 窗口函数
    语法结构窗口函数的语法结构:函数OVER([PARTITIONBY字段名ORDERBY字段名ASC|DESC])函数OVER窗口名…WINDOW窗口名AS([PARTITIONBY字段名ORDERBY字......
  • navicate12 连接MySQL8 报错
      mysql>selectuser,plugin,hostfromuserwhereuser='root';+------+-----------------------+------+|user|plugin|host|+------+------......
  • MySQL进阶篇
    1.存储引擎1.1MySQL体系结构 连接层  最上层是一些客户端和链接服务,包含本地sock通信和大多数基于客户端/服务端工具实现的类似于TCP/IP的通信。主要完成......
  • Mysql的INTERVAL()函数和INTERVAL关键字
    Mysql的INTERVAL()函数和INTERVAL关键字  一,INTERVAL()函数INTERVAL()函数可以返回分段后的结果,语法如下:INTERVAL(N,N1,N2,N3,..........)其中,N是要判断的数值,N1,N2......
  • mysql 查询30分钟内的验证码
    mysql查询30分钟内的验证码 selectt.`value`as`value`fromt_message_infot wheret.user_name=13072281151ANDt.`key`=1ANDt.is_use=0ANDt.crea......