有关存储过程的问题 [英] issue regarding stored procedure

查看:71
本文介绍了有关存储过程的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅获取每年3月值的财政年度

how to get the financial year only for mar values for every year

推荐答案

您好,

试试这个,
Hi,

try this,
SELECT * FROM YourTable WHERE DATEPART(MONTH, FinancialYear)= 3

-- FinancialYear would be column of YourTable


如果月份为3月,则此查询将提供表格中的详细信息.


this query will give details from the table if the month is MARCH.


根据您在问题中给我们提供的信息,以下是您必须适应特定环境的答案但应该起作用:
Based upon what little you gave us in the question, here is an answer that you will have to adapt to your particular environment but which should work:
SELECT rowMonth, rowYear, SUM(rowMoneyData) AS Total
FROM (
   SELECT Month(rowDate) AS rowMonth, Year(rowDate) AS rowYear, rowMoneyData
   FROM yourTable) AS convertedTable
WHERE rowMonth = 3
GROUP BY rowYear, rowMonth


它的作用是首先创建一个子查询,该子查询仅包含您需要的数据,并为您提供每一行的月份和年份数字.然后,在主查询中使用该子查询进行分组和过滤.由于您只需要3月的数据,因此我按月份3进行了过滤.

您可以在没有子查询的情况下执行此操作,但它的性能不佳,因为您需要将一次转换为一个月而不是一次(一次在Group By中,一次在Where中).
该查询的结果将是每年3月总计的单独一行.


What this does is it first creates a sub-query that includes just the data you need and gives you month and year numbers for each row. Then we use that sub-query in our main query to group by and filter. Since you wanted just March data, I filtered it by month number 3.

You could do this without the sub-query but it wouldn''t be as performant because you would need to do the conversion to month twice instead of once (once in the Group By and once in the Where).

The results of this query would be the total for March for each year on a separate line.


这篇关于有关存储过程的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆