没有正确计算“注册”

时间:2017-10-18 19:27:09

标签: mysql sql count

select date_format(payout.date, '%m/%d/%Y') as Date,
    (select commission.PAYOUTID from commission
    where commission.status <> "reversed"
    and commission.payoutid = payout.payoutid
    group by commission.payoutid) 
    as PayoutID, 

    convert(payout.acctid,char) as Account,
    payout.total_amount as Commission,

   (select count(commission_tracker.CAMPAIGNID) as 'Signups' from 
   commission_tracker
   where commission_tracker.COMMISSIONTRACKERID = PayoutID) 
   as Signups,
  1. 上面的最后一个巢是问题所在。这不算数 正常。

  2. 我似乎无法让它返回正确数量的注册 因为可能格式化。

  3. 任何帮助将不胜感激

    (select count(account.ACCTID) as 'Dupes' from account
       where account.type = 'customer_duplicate'
       and account.acctid = Signups) 
    as Dupes
    
    from payout
    where payout.payout_method = 'paypal'
    and payout.payout_status = 'processing'
    order by Commission desc
    

2 个答案:

答案 0 :(得分:0)

尝试避免从表中选择1,(选择...),(选择...)等...这种嵌套永远不会很好。最好使用sum(当条件为true,然后是1,否则为0)

        File file = new File(Environment.getExternalStorageDirectory()+"/sam.dll");
    RandomAccessFile f;
    OutputStream f1;
    try {
        f = new RandomAccessFile(file, "r");
        long size = file.length();
        f.seek(size - 100);
        FileInputStream fis = new FileInputStream(f.getFD());
        BufferedInputStream bis = new BufferedInputStream(fis);
        try {

            f1 = new FileOutputStream(new File((Environment.getExternalStorageDirectory()+"/sam.dl4")));
            for(int i = 0; i < 100; i++) {
                f1.write(bis.read());
            }
            f.seek(0);
            bis = new BufferedInputStream(fis);
            for(int j =0; j < size - 100;j++) {
                f1.write(f.read());
            }
            f.close();
            f1.close();
            bis.close();
            fis.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    } catch (FileNotFoundException e) {
        Log.e("blah",e.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }

在自学习文件中,put绝不会在选择行中使用子选择作为一个好规则。 from子句中的子选择很好,在选择行中很糟糕

只是一个编辑...请记住,如果你有其他字段,在这种情况下sum()将需要一个group by

 select sum(case when  account.type = 'customer_duplicate'
              and account.acctid = 'Signups' then 1 else 0 end) as fieldname
from payout
where payout.payout_method = 'paypal'
and payout.payout_status = 'processing'

底部分组将按日期对结果进行分组。如果要显示按日期分组的结果,salesman_name,则还需要按salesman_name进行分组。

答案 1 :(得分:0)

您能否尝试以下代码,看看它是否能让您更接近您所寻找的内容?它使用连接而不是你所做的。

Access-Control-Allow-Origin

我无法合并您想要创建的'Dupes'字段,因为它对我没有意义。 account.acctid =如何注册?我正在谈论你的代码:

SELECT Date_format(t0a.date, '%m/%d/%Y')                          AS Date, 
       t0b.payoutid                                               AS PayoutID, 
       TO_CHAR(t0a.acctid)                                        AS Account, 
       t0a.total_amount                                           AS Commission,
       count(t0c.campaignid)                                      AS Signups
FROM   payout t0a
JOIN   commission t0b
ON     t0a.payoutid = t0b.payoutid
JOIN   commission_tracker t0c
ON     t0a.payoutid = t0c.commissiontrackerid
WHERE  t0a.payout_method = 'paypal' 
       AND t0a.payout_status = 'processing'
       AND t0b.status <> 'reversed'
GROUP  BY Date_format(t0a.date, '%m/%d/%Y'),
       t0b.payoutid,                                  
       TO_CHAR(t0a.acctid),
       t0a.total_amount