• MSSQL中按时间字段分组查询,并在查询结果中显示所有分组数据列 按时
  • 其它
    1.00元

--查询上月入库数量 SELECT    t3.FNUMBER AS '物料编码',    t1.FDATE AS '入库时间',    SUM( t2.FREALQTY ) AS '上月累计入库数量' FROM    T_PRD_INSTOCK t1    LEFT JOIN T_PRD_INSTOCKENTRY t2 ON t1.FID = t2.FID    LEFT JOIN T_BD_MATERIAL t3 ON t2.FMATERIALID = t3.FMATERIALID WHERE    DATEDIFF(month,t1.FDATE,GETDATE())=1 GROUP BY    t1.FDATE,    t3.FNUMBER ORDER BY    t1.FDATE DESC    --查询本月入库数量 SELECT    t3.FNUMBER AS '物料编码',    t1.FDATE AS '入库时间',    sum( t2.FREALQTY ) AS '本月累计入库数量' FROM    T_PRD_INSTOCK t1    LEFT JOIN T_PRD_INSTOCKENTRY t2 ON t1.FID = t2.FID    LEFT JOIN T_BD_MATERIAL t3 ON t2.FMATERIALID = t3.FMATERIALID WHERE    DATEDIFF(month,t1.FDATE,GETDATE())=0           GROUP BY    t1.FDATE,    t3.FNUMBER ORDER BY    t1.FDATE DESC

  • 西西    2020-04-16 16:01:23
  • 阅读 1632    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信