计费/ paydate的AVG我有两个表: t_address - >与用户地址 t_billing - >随着对t_address用户的PHP/MySQL - >每用户
他们是由相关的计费信息t_billing.bil_addressref = t_address.adr_ref
在计费表,我有一个字段 bil_date - >日期法案已发行时/发送 bil_paydate - >日期时,法案已纳了
我没有喜欢,确定了“最差的付款人“,意思是o谁需要平均最长的时间来支付账单。
例如:
号 - bil_date - bil_paydate - adr_ref
1 - 2017年1月1日 - 2017年1月10日 - 1
2 - 2017年2月1日 - 2017-02-10 - 1
3 - 2017-03-01 - 2017-03-05 - 1
4 - 2017-04-01 - 2017-04-05 - 1
5 - 2017-01-01 - 2017-01-30 - 2
6 - 2017-03-01 - 2017-03-30 - 2
...
所以
药品不良反应2平均付费时间29天
为ADR 1平均付费时间6.5天
我想有前5名成绩最糟糕的纳税人,降到最差。
我试了几个疑问和想法,但没来翻过正确的想法:/
有什么建议?谢谢,斯蒂芬。
,你能否告诉我们到目前为止你已经尝试了什么问题? – Optimae
最后一次尝试是在t_billing中将所有adr_ref区分开来,其中paydate IS NOT NULL,然后在一段时间内(知道它不会导致我想要的结果)。甚至没有得到一个值AMT:/'选择bil_addressref,adr_lastname,adr_firstname,AVG(DATEDIFF(TO_DAYS(bil_paydate),TO_DAYS(bil_date)))AS平均,adr_ref FROM t_billing \t \t \t \t \t \t \t INNER JOIN t_address ON bil_addressref = adr_ref \t \t \t \t \t \t \t \t \t \t \t \t \t \t WHERE bil_mandantref = '$ mandantref' \t \t \t \t \t \t \t AND bil_addressref ='“。$ rowWorstPayerMain ['bil_addressref']。“” \t \t \t \t \t \t \t GROUP BY bil_addressref \t \t \t \t \t \t \t ORDER BY平均ASC' –