Mysql / PHP数据透视表过滤器

时间:2017-12-05 10:23:06

标签: php mysql

在没有欢乐的情况下尝试了几天,所以我想问这个问题吗?

我有一个基于mysql查询的php数据透视图,它工作得很好,但我想有一个外部过滤器多年......目前我只能包括2017年例如在where子句,我试图删除,但似乎无法计算出如何在负载上显示当前年份数据,然后通过用户输入年份对其进行过滤。 Currenbtly我每年有5张不同的桌子,这很麻烦,这可能吗?

SELECT * FROM 
  (SELECT c.Adviser,
  Sum(Case When Month(i.signedupdate) = 1 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Jan,
  Sum(Case When Month(i.signedupdate) = 2 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Feb,
  Sum(Case When Month(i.signedupdate) = 3 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Mar,
  Sum(Case When Month(i.signedupdate) = 4 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Apr,
  Sum(Case When Month(i.signedupdate) = 5 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) May,
  Sum(Case When Month(i.signedupdate) = 6 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Jun,
  Sum(Case When Month(i.signedupdate) = 7 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Jul,
  Sum(Case When Month(i.signedupdate) = 8 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Aug,
  Sum(Case When Month(i.signedupdate) = 9 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Sept,
  Sum(Case When Month(i.signedupdate) = 10 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Oct,
  Sum(Case When Month(i.signedupdate) = 11 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Nov,
  Sum(Case When Month(i.signedupdate) = 12 Then i.comms + i.broker_fee + i.legal_fees Else 0 End) Dece,
  Sum(i.comms + i.broker_fee + i.legal_fees) As Total
From
  tbl_lead i Inner Join
  tbl_clients c On c.client_id = i.client_id
Where
    Year(i.signedupdate)= 2017
Group By c.Adviser with rollup) As t

0 个答案:

没有答案