以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 数据库统计 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=191839) |
||||
-- 作者:BG小白 -- 发布时间:2024/5/11 1:42:00 -- 数据库统计 此主题相关图片如下:1.png [此贴子已经被作者于2024/5/11 2:07:28编辑过]
|
||||
-- 作者:BG小白 -- 发布时间:2024/5/11 2:06:00 -- SE LECT {SDPHDMX}.DJBH AS 批次号, {GONGHUOSHANG}.GHSMC AS 供货商, SUM({SDPHDMX}.SL) AS 配货数, SUM(fQuantity) AS 销售数 FROM ((({SDPHD} INNER JOIN {SDPHDMX} ON {SDPHD}.DJBH = {SDPHDMX}.DJBH) INNER JOIN {shangpin_A} ON {SDPHDMX}.SPDM = {shangpin_A}.SPDM) INNER JOIN {GONGHUOSHANG} ON {SHANGPIN_A}.GHSDM = {GONGHUOSHANG}.GHSDM) INNER JOIN {SG_Gatherings} ON {SDPHDMX}.spdm = {SG_Gatherings}.vstyle GROUP BY {SDPHDMX}.DJBH,{GONGHUOSHANG}.GHSMC ORDER BY 批次号 DESC 这是第二张图片的代码
[此贴子已经被作者于2024/5/11 2:06:55编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2024/5/11 8:58:00 -- 请提供实例测试 |
||||
-- 作者:BG小白 -- 发布时间:2024/5/11 14:02:00 --
|
||||
-- 作者:有点蓝 -- 发布时间:2024/5/11 14:18:00 -- 举一个具体的批号说明一下,比如上面说的【实际销售数字是6件】,这个6是怎么查的? 还有各个表的关系麻烦说明一下
[此贴子已经被作者于2024/5/11 14:19:12编辑过]
|
||||
-- 作者:BG小白 -- 发布时间:2024/5/11 15:21:00 -- SG_Gatherings这个是零售的货号和件数,SDPHD是配货单据号和日期,SDPHDMX是根据单据号关联的单据内的货号和数量,GONGHUOSHANG是供货商信息,SHANGPIN_A是根据货号关联的供货商代码,表1是根据配货单据号关联的货号查询的供货商配货数量,这里的数量是对的,表2是根据配货单号关联了,供货商的信息,想统计每个配货单号里面每个供货商配货数量和销售数量,表3就是查询了每个供货商销售的数量,6件就是零售单里面这个供货商卖的总件数,但是在表2里面这个供货商统计出来的销售数量就是16件 |
||||
-- 作者:BG小白 -- 发布时间:2024/5/11 15:21:00 -- 最终想实现表2的效果 |
||||
-- 作者:有点蓝 -- 发布时间:2024/5/11 16:08:00 -- 试试 select c.批次号,c.供货商,c.配货数,d.销售数 from (SELECT {SDPHDMX}.DJBH AS 批次号, {GONGHUOSHANG}.GHSDM ,{GONGHUOSHANG}.GHSMC AS 供货商, SUM({SDPHDMX}.SL) AS 配货数 FROM ((({SDPHD} INNER JOIN {SDPHDMX} ON {SDPHD}.DJBH = {SDPHDMX}.DJBH) INNER JOIN {shangpin_A} ON {SDPHDMX}.SPDM = {shangpin_A}.SPDM) INNER JOIN {GONGHUOSHANG} ON {SHANGPIN_A}.GHSDM = {GONGHUOSHANG}.GHSDM) GROUP BY {SDPHDMX}.DJBH,{GONGHUOSHANG}.GHSDM ,{GONGHUOSHANG}.GHSMC ) as c inner join (select a.GHSDM, SUM(fQuantity) AS 销售数 from {shangpin_A} as a inner join {SG_Gatherings} as b on a.SPDM = b.vstyle group by a.GHSDM) as d on c.GHSDM = d.GHSDM ORDER BY c.批次号 DESC
|
||||
-- 作者:BG小白 -- 发布时间:2024/5/11 16:26:00 -- 蓝老师,我用的是sql,这个abc该如何修改,看了半天没有明白 |
||||
-- 作者:有点蓝 -- 发布时间:2024/5/11 16:30:00 -- select c.批次号,c.供货商,c.配货数,d.销售数 from (SELECT {SDPHDMX}.DJBH AS 批次号, {GONGHUOSHANG}.GHSDM ,{GONGHUOSHANG}.GHSMC AS 供货商, SUM({SDPHDMX}.SL) AS 配货数 FROM {SDPHD} INNER JOIN {SDPHDMX} ON {SDPHD}.DJBH = {SDPHDMX}.DJBH INNER JOIN {shangpin_A} ON {SDPHDMX}.SPDM = {shangpin_A}.SPDM INNER JOIN {GONGHUOSHANG} ON {SHANGPIN_A}.GHSDM = {GONGHUOSHANG}.GHSDM GROUP BY {SDPHDMX}.DJBH,{GONGHUOSHANG}.GHSDM ,{GONGHUOSHANG}.GHSMC ) as c inner join (select a.GHSDM, SUM(fQuantity) AS 销售数 from {shangpin_A} as a inner join {SG_Gatherings} as b on a.SPDM = b.vstyle group by a.GHSDM) as d on c.GHSDM = d.GHSDM ORDER BY c.批次号 DESC |