0

これらのクエリは個別に 100% 実行されます

クエリ1

SELECT year_entered, 
   month_entered,
   IFNULL(amount - @n, 0) amount_diff,
   @n := amount current_amount
  FROM
 (SELECT YEAR(date_entered) year_entered, 
     MONTHNAME(date_entered) month_entered, 
     SUM(amount) amount
FROM opportunities
INNER JOIN opportunities_cstm
ON ( opportunities.id = opportunities_cstm.id_c)
WHERE 
YEAR(opportunities.date_entered) >= YEAR(CURDATE())
AND  (`opportunities`.`deleted` <> '1') AND 
(opportunities_cstm.interest_level_c = 'Ultraspin'
OR 
opportunities_cstm.interest_level_c = 'Mycelx')
GROUP BY YEAR(date_entered), MONTH(date_entered)) q, 
(SELECT @n := NULL) n

クエリ 2

SELECT year_entered, 
   month_entered,
   IFNULL(id - @n, 0) id_diff,
       @n := id current_id
  FROM
 (SELECT YEAR(date_entered) year_entered, 
         MONTHNAME(date_entered) month_entered, 
         COUNT(id) id
    FROM opportunities
    INNER JOIN opportunities_cstm
    ON ( opportunities.id = opportunities_cstm.id_c)
 WHERE 
 YEAR(opportunities.date_entered) >= YEAR(CURDATE())
 AND  (`opportunities`.`deleted` <> '1') AND 
 (opportunities_cstm.interest_level_c = 'Ultraspin'
 OR 
 opportunities_cstm.interest_level_c = 'Mycelx')
   GROUP BY YEAR(date_entered), MONTH(date_entered)) q, 
 (SELECT @n := NULL) n
 ON year_entered = year_entered

1つのクエリで金額の違いとカウントの違いをどのように計算する必要がありますか、ジャスパーレポートを使用してこれを報告したいですか、またはPHPの戻り行で誰かが助けることができますか?

両方のクエリを取得して並べて返す方法がわからないだけです

4

2 に答える 2

0
SELECT year_entered, 
       month_entered,
       IFNULL(amount - @n, 0) amount_diff,
       IFNULL(id - @a, 0) id_diff,
       @n := amount current_amount,
       @i := id current_id
FROM (SELECT YEAR(date_entered) year_entered, 
             MONTHNAME(date_entered) month_entered, 
             SUM(amount) amount,
             COUNT(id) id
      FROM opportunities
      INNER JOIN opportunities_cstm
      ON ( opportunities.id = opportunities_cstm.id_c)
      WHERE YEAR(opportunities.date_entered) >= YEAR(CURDATE())
            AND  (`opportunities`.`deleted` <> '1')
            AND (opportunities_cstm.interest_level_c = 'Ultraspin'
            OR opportunities_cstm.interest_level_c = 'Mycelx')
      GROUP BY YEAR(date_entered), MONTH(date_entered)) q,
     (SELECT @n := NULL, @i := NULL) n
于 2013-05-06T14:31:49.603 に答える
0

これを試して:

    SELECT year_entered, 
   month_entered,
   query1.amount_diff,
   query2.id_diff FROM
        (SELECT year_entered, 
           month_entered,
           IFNULL(amount - @n, 0) amount_diff,
           @n := amount current_amount
          FROM
         (SELECT YEAR(date_entered) year_entered, 
             MONTHNAME(date_entered) month_entered, 
             SUM(amount) amount
        FROM opportunities
        INNER JOIN opportunities_cstm
        ON ( opportunities.id = opportunities_cstm.id_c)
        WHERE 
        YEAR(opportunities.date_entered) >= YEAR(CURDATE())
        AND  (`opportunities`.`deleted` <> '1') AND 
        (opportunities_cstm.interest_level_c = 'Ultraspin'
        OR 
        opportunities_cstm.interest_level_c = 'Mycelx')
        GROUP BY YEAR(date_entered), MONTH(date_entered)) q, 
        (SELECT @n := NULL) n) query1 JOIN (
            SELECT year_entered, 
               month_entered,
               IFNULL(id - @n, 0) id_diff,
                   @n := id current_id
              FROM
             (SELECT YEAR(date_entered) year_entered, 
                     MONTHNAME(date_entered) month_entered, 
                     COUNT(id) id
                FROM opportunities
                INNER JOIN opportunities_cstm
                ON ( opportunities.id = opportunities_cstm.id_c)
             WHERE 
             YEAR(opportunities.date_entered) >= YEAR(CURDATE())
             AND  (`opportunities`.`deleted` <> '1') AND 
             (opportunities_cstm.interest_level_c = 'Ultraspin'
             OR 
             opportunities_cstm.interest_level_c = 'Mycelx')
               GROUP BY YEAR(date_entered), MONTH(date_entered)) q, 
             (SELECT @n := NULL) n
             ON year_entered = year_entered
        ) query2 ON query1.year_entered = query2.year_entered AND query1.month_entered = query2.month_entered
于 2013-05-06T14:28:24.153 に答える