SELECT DATEPART(mm,tdjd.oper_date) as 月份,SUM(pos_amt-pos_ret_amt) as 金额 FROM t_da_jxc_daysum tdjd LEFT JOIN t_bd_item_info tbii ON tbii.item_no = tdjd.item_no LEFT JOIN t_bd_item_cls tbic ON tbic.item_clsno = tbii.item_clsno LEFT JOIN t_bd_branch_info tbbi ON LEFT(tbbi.branch_no,4) = tdjd.branch_no WHERE tdjd.oper_date BETWEEN convert(VARCHAR(7), DATEADD(mm,-11,GETDATE()) ,23) AND convert(varchar(10), GETDATE() ,23) ${IF(季节=="","","AND tbii.season_no = '"+季节+"'")} ${IF(品牌=="","","AND LEFT(tbii.item_clsno,2)='"+品牌+"'")} ${IF(大类=="","","AND LEFT(tbii.item_clsno,4)='"+大类+"'")} ${IF(门店=="","","AND tbbi.branch_no = '"+门店+"'")} AND LEFT(tbii.item_clsno,2) IN('01','02','03','04','07','08') GROUP BY CONVERT(varchar(7),tdjd.oper_date,23),datepart(mm,tdjd.oper_date) ORDER BY CONVERT(varchar(7),tdjd.oper_date,23)
时间: 2023-05-14 15:05:26 浏览: 223
这是一个 SQL 查询语句,用于查询某个时间段内不同条件下的销售金额。其中,季节、品牌、大类、门店是可选的筛选条件,如果没有指定,则不会影响查询结果。由于我是一个 AI,我无法直接执行 SQL 查询,但是我可以帮你解读这个查询语句,如果你有相关的数据表和数据,可以尝试在数据库中执行这个查询语句,以获得相应的结果。
相关问题
SELECT DATEPART(YEAR, t_kqlist23.RQCHAR) AS [Year], DATEPART(MONTH, t_kqlist23.RQCHAR) AS [Month], t_kqlist23.BSIN AS BSIN, t_kqlist23.ESOUT AS ESOUT, T_JKDX.YDJBH AS card_number, T_BM_BM.BMMC AS department, T_BM_ZW.ZWMC AS duties, T_JKDX.XM AS name, T_BM_GZ.GZMC AS work_type_name, COUNT(*) AS [Count] FROM [cxrydw].[guoxw].[t_kqlist23] AS t_kqlist23 LEFT JOIN [cxrydw].[guoxw].[T_JKDX] AS T_JKDX ON T_JKDX.XTBH = t_kqlist23.XTBH LEFT JOIN [cxrydw].[guoxw].[T_BM_BM] AS T_BM_BM ON T_BM_BM.BMBM = T_JKDX.BMBM LEFT JOIN [cxrydw].[guoxw].[T_BM_ZW] AS T_BM_ZW ON T_BM_ZW.ZWBM = T_JKDX.ZWBM LEFT JOIN [cxrydw].[guoxw].[T_BM_GZ] AS T_BM_GZ ON T_BM_GZ.GZBM = T_JKDX.GZBM WHERE DATEPART(YEAR, t_kqlist23.RQCHAR) = 2023 AND t_kqlist23.XTBH = '17' GROUP BY DATEPART(YEAR, t_kqlist23.RQCHAR), DATEPART(MONTH, t_kqlist23.RQCHAR), t_kqlist23.BSIN, t_kqlist23.ESOUT, T_JKDX.YDJBH, T_BM_BM.BMMC, T_BM_ZW.ZWMC, T_JKDX.XM, T_BM_GZ.GZMC ORDER BY [Year], [Month] 查询出每月的数据条数
这个SQL查询语句是用于查询指定年份和XTBH的每个月的数据条数。它从多个表中选择了一些列,并进行了一系列的JOIN操作。然后,使用DATEPART函数提取出年份和月份,并对这些列进行分组。最后,使用COUNT函数计算每个组的数据条数,并按年份和月份进行排序。
注意:这个查询语句是基于SQL Server的语法,如果你使用的是其他数据库,可能需要进行适当的调整。
SELECT DATEPART(YEAR, t_kqlist23.RQCHAR) AS [Year], DATEPART(MONTH, t_kqlist23.RQCHAR) AS [Month], t_kqlist23.BSIN AS BSIN, t_kqlist23.ESOUT AS ESOUT, T_JKDX.YDJBH AS card_number, T_BM_BM.BMMC AS department, T_BM_ZW.ZWMC AS duties, T_JKDX.XM AS name, T_BM_GZ.GZMC AS work_type_name, COUNT(*) AS [Count] FROM [cxrydw].[guoxw].[t_kqlist23] AS t_kqlist23 LEFT JOIN [cxrydw].[guoxw].[T_JKDX] AS T_JKDX ON T_JKDX.XTBH = t_kqlist23.XTBH LEFT JOIN [cxrydw].[guoxw].[T_BM_BM] AS T_BM_BM ON T_BM_BM.BMBM = T_JKDX.BMBM LEFT JOIN [cxrydw].[guoxw].[T_BM_ZW] AS T_BM_ZW ON T_BM_ZW.ZWBM = T_JKDX.ZWBM LEFT JOIN [cxrydw].[guoxw].[T_BM_GZ] AS T_BM_GZ ON T_BM_GZ.GZBM = T_JKDX.GZBM WHERE DATEPART(YEAR, t_kqlist23.RQCHAR) = 2023 AND t_kqlist23.XTBH = '17' GROUP BY DATEPART(YEAR, t_kqlist23.RQCHAR), DATEPART(MONTH, t_kqlist23.RQCHAR), t_kqlist23.BSIN, t_kqlist23.ESOUT, T_JKDX.YDJBH, T_BM_BM.BMMC, T_BM_ZW.ZWMC, T_JKDX.XM, T_BM_GZ.GZMC ORDER BY [Year], [Month] 改成查询出每月的数据条数
这个查询已经是用于查询每月的数据条数了。它在SELECT子句中使用了COUNT(*)函数来统计每个月的数据条数,并将结果命名为[Count]。在GROUP BY子句中,按照年份、月份、BSIN、ESOUT、card_number、department、duties、name和work_type_name进行分组。最后使用ORDER BY子句按照年份和月份进行排序。所以这个查询已经可以得到每个月的数据条数了。
阅读全文