Mysql 按周结束数的SQL总数分组;月刊年初至今数字

Mysql 按周结束数的SQL总数分组;月刊年初至今数字,mysql,sql,sql-server-2008-r2,Mysql,Sql,Sql Server 2008 R2,我很难按周末、月至今和年至今的总数进行分组。当前,通过我的查询,我得到了这个输出 (No column name) Received App # Received App $ (No column name) Loan Closed # Loan Closed $ Applications Received 2 $500,000.00 New Loans Closed 1 $250,000.00

我很难按周末、月至今和年至今的总数进行分组。当前,通过我的查询,我得到了这个输出

(No column name)        Received App #  Received App $  (No column name)    Loan Closed #   Loan Closed $
Applications Received   2               $500,000.00     New Loans Closed    1               $250,000.00
而不是上面,我希望得到这样的输出

Applications Received 2  $500,000.00 
New Loans Closed      1  $250,000.00 
请看下面我的查询:

    select 

    'Applications Received',
    count(case when pd.Status_four_Dt between '1/1/2014' and '2/1/2014' then pd.loan_amt end) as 'Received App #',
    sum(case when pd.Status_four_Dt between '1/1/2014' and '2/1/2014' then pd.loan_amt end) as 'Received App $',
    'New Loans Closed',
    count(case when pd.Status_ten_Dt between '1/1/2014' and '2/1/2014' then pd.loan_amt end) as 'Loan Closed #',
    sum(case when pd.Status_ten_Dt between '1/1/2014' and '2/1/2014' then pd.loan_amt end) as 'Loan Closed $'


    from pipe_deal pd
     left join pipe_quote pq
     on pd.id = pq.deal_id

where
pd.record_type_lkup ='dl'
and pd.company_identity_id = 2
and ((pd.status_lkup_id in(14,16,17,18,19,20,21,22,23) and pq.active_yn = 'y') or (pd.status_lkup_id = 13 and pq.active_yn is null) or (pd.status_lkup_id = 24 and (pq.active_yn = 'y' or pq.active_yn is null)))
and pd.delete_yn = 'N'
and pd.Status_One_Dt > '01/01/2008'
and (pd.EMP_OFFICE_LKUP_Id <> 192 or pd.EMP_OFFICE_LKUP_Id is null) 


--group by
--(case 
--when pd.Status_four_Dt>0  then 'Received Application'
--when  pd.Status_ten_Dt>0 then 'Loans Closed' 
--end)
因此,基本上,收到的申请和新贷款关闭的总数是前一周结束的一周的总数,我只是无法以输出所需的方式对其进行分组 收到申请书2$500000.00 新贷款结清1$250000.00

我想要一种方法,将收到的申请和结清的新贷款分组,将它们放在行而不是列中


请帮助。

我对您的数据结构不太熟悉,无法为您提供准确的查询,但您可以使用UNION ALL来完成此操作

您将只希望选择应用程序收到的数据,这些数据看起来是COUNT*和SUMpd.loan\u amt,其中pd.Status\u four\u Dt介于等之间,然后将该结果与给出应用程序的数据(看起来是COUNT*和SUMpd.loan\u amt,其中pd.Status\u ten\u Dt介于两者之间)合并。。。等等。您可以只为第一列选择文本,例如,收到的申请为描述、计数*和SUMloan金额,其中pd.Status\u four\u Dt介于等等之间,然后将结果与新贷款关闭的结果合并


有意义吗?

1。使用日期和时间的适当日期/时间数据类型。一旦完成了上面的步骤1,考虑提供适当的DDL和/或SqLFIDLE连同期望的结果集。您使用的是MySQL还是M$SQL?我使用的是MS SQL R2……上面提供了所需的结果集……基本上收到的应用程序和贷款关闭数据都是日期,所以,如果我想知道收到了多少申请,我会过滤数据集中的received application列,只选择上周或当月的日期。。。。希望这对理解数据有一定的启发…好的。。。因此,编写一个查询,只给出收到的应用程序。写另一个,只给你贷款关闭。将查询合并在一起,就完成了。