0

これは私のコードですが、機能していません:

$select = $db->select()
             ->from(array('p' => 'products'), 'p.product_id')
             ->columns(array('x' => new Zend_Db_Expr('(SELECT...)'                    
                       )))
             ->where('x = ?', 'value');
             // Alternatively use columns('p.product_name')

xを取得してwhere句で競合させるにはどうすればよいですか?

これが実際のクエリです。

SELECT `abstract_submission`.*,
   (SELECT GROUP_CONCAT(CONCAT(user.firstName, " ", user.lastName) SEPARATOR ",")
           FROM mamba_event.abstract_submission_reviewer reviewer INNER JOIN                 
           mamba_account.account_user user ON user.id = reviewer.userId
       WHERE reviewer.submissionId = mamba_event.abstract_submission.id AND
       user.isEnabled = 1) 
    AS `reviewers`,
   (SELECT GROUP_CONCAT(CONCAT(author.firstName, " ", author.lastName) SEPARATOR ",")
           FROM mamba_event.abstract_author author INNER JOIN
           mamba_event.abstract_submission_author map ON author.id = map.authorId
       WHERE map.submissionId = mamba_event.abstract_submission.id)
   AS `allAuthors`,
   (SELECT COUNT(`abstract_paper`.`id`) FROM `mamba_event`.`abstract_paper`
      WHERE `abstract_paper`.`submissionId` = `abstract_submission`.`id`)
   AS `numPapers`,
   (SELECT `paperNumber` FROM `mamba_event`.`abstract_paper`
      WHERE `abstract_paper`.`submissionId` = `abstract_submission`.`id` AND
          `abstract_paper`.`currentStatus` = 3 LIMIT 1)
    AS `acceptedPaperNumber`,
    (SELECT IF ((COUNT(1) > 0), 'Paper has been uploaded','None') AS hasUploadedPaper
         FROM `mamba_event`.`abstract_paper` paper
      WHERE paper.submissionId = `mamba_event`.`abstract_submission`.`id`) 
     AS `hasUploadedPaper`,
    (SELECT GROUP_CONCAT(CONCAT(user.firstName, " ", user.lastName) SEPARATOR ",")
       FROM `mamba_event`.`abstract_submission_reviewer` reviewer INNER JOIN 
            `mamba_account`.`account_user` user ON user.id = reviewer.userId
         WHERE reviewer.submissionId = `mamba_event`.`abstract_submission`.`id`
         AND reviewer.hasConflictOfInterest = 1
         AND user.isEnabled = 1)
     AS `reviewersWithConflict`,
    (SELECT AVG(`score`) FROM `mamba_event`.`abstract_submission_score`
        WHERE `submissionId` = `abstract_submission`.`id`)
     AS `averageScore`,
     (SELECT AVG(`score`) FROM `mamba_event`.`abstract_paper_score`, `mamba_event`.`abstract_paper`
        WHERE `abstract_paper_score`.`paperId` = `abstract_paper`.`id`
          AND `abstract_paper`.`submissionId` = `abstract_submission`.`id`
          AND (`abstract_paper`.`currentStatus` = 1
          OR `abstract_paper`.`currentStatus` = 3))
      AS `averagePaperScore`,
      (SELECT AVG(`score`*`scoreWeight`) FROM `mamba_event`.`abstract_submission_score` INNER JOIN
           `mamba_event`.`abstract_request_criteria` ON `criteriaId` = `abstract_request_criteria`.`id`
         WHERE `submissionId` = `abstract_submission`.`id`) 
      AS `averageWeightedScore`,
     (SELECT AVG(`score`*`scoreWeight`) FROM `mamba_event`.`abstract_paper_score` JOIN
          `mamba_event`.`abstract_paper` INNER JOIN
          `mamba_event`.`abstract_request_criteria` ON
          `criteriaId` = `abstract_request_criteria`.`id`
       WHERE `abstract_paper_score`.`paperId` = `abstract_paper`.`id`
       AND `abstract_paper`.`submissionId` = `abstract_submission`.`id`
       AND (`abstract_paper`.`currentStatus` = 1
       OR `abstract_paper`.`currentStatus` = 3))
     AS `averageWeightedPaperScore`, `author`.`email`
     AS `authorEmail`, `author`.`salutation`
     AS `authorTitle`, `author`.`firstName`
     AS `authorFirstName`, `author`.`lastName`
     AS `authorLastName`, `author`.`organisation`
     AS `authorOrganisation`, `author`.`position`
     AS `authorPosition`, `author`.`department`
     AS `authorDepartment`, `author`.`phone`
     AS `authorPhone`, `author`.`fax`
     AS `authorFax`, `address`.`line1`
     AS `addressLine1`, `address`.`line2`
     AS `addressLine2`, `address`.`line3`
     AS `addressLine3`, `address`.`line4`
     AS `addressLine4`, `address`.`city`
     AS `addressCity`, `address`.`stateCode`
     AS `addressStateCode`, `address`.`countryCode`
     AS `addressCountryCode`, `address`.`postalCode`
     AS `addressPostalCode`, `author`.`biography`
     AS `authorBiography`, `request`.`title`
     AS `request`, `request`.`blindReview`, `request`.`hasCustomTypes`, `file`.`content_type`, `file`.`original_filename` AS `filename`, `author`.`speakerId`,
     (SELECT GROUP_CONCAT(
                          CONCAT('',ifnull(author.firstName,'-'),' ',
                                    ifnull(author.lastName,'-'),' 
                                    (',ifnull(author.organisation,'-'),', 
                                    ',ifnull(author.authorCountryCode,'-'),')')
                        SEPARATOR ",")
              FROM `mamba_event`.`abstract_author` author LEFT JOIN 
                    `mamba_event`.`abstract_submission_author` sa
                 ON sa.authorId = author.id
              WHERE sa.submissionId = `abstract_submission`.`id`)
           AS `authorDetails`,
          (SELECT GROUP_CONCAT(`field`.`fieldValue`)
               FROM `mamba_abstract`.`author_field_value_varchar` `field` 
                 WHERE `field`.`fieldId` = '2185'
                 AND `field`.`authorId` = `abstract_submission`.`presenterId`)
          AS `field2185`,
      (SELECT GROUP_CONCAT(`field`.`fieldValue`)
              FROM `mamba_abstract`.`author_field_value_varchar` `field`
                 WHERE `field`.`fieldId` = '2335'
                   AND `field`.`fieldValue` = 'BSCS'
                   AND `field`.`authorId` = `abstract_submission`.`presenterId`)
      AS `field2335`,
     (SELECT GROUP_CONCAT(`field`.`fieldValue`)
         FROM `mamba_abstract`.`author_field_value_varchar` `field`
            WHERE `field`.`fieldId` = '2336'
            AND `field`.`authorId` = `abstract_submission`.`presenterId`)
      AS `field2336` FROM `mamba_event`.`abstract_submission`
 INNER JOIN `mamba_event`.`abstract_request` AS `request` ON requestId = request.id
 LEFT JOIN `mamba_account`.`account_file` AS `file` ON fileId = file.id
 INNER JOIN `mamba_event`.`abstract_author` AS `author` ON `presenterId` = `author`.`id`
 LEFT JOIN `mamba_general`.`address` ON `author`.`addressId` = `address`.`id` WHERE ((`abstract_submission`.`isEnabled` = '1') AND (`abstract_submission`.`eventId` = '1893')) AND (`field2335` LIKE "%BSCS%") ORDER BY `request` asc LIMIT 15
4

1 に答える 1

1

HAVINGMuhammad Zeeshanが言ったように、あなたはそれを行うことができます。

$select = $db->select()
    ->from(array('p' => 'products'), 'p.product_id')
    ->columns(array('x' => new Zend_Db_Expr('(SELECT...)')))
    ->having('x = ?', 'value');
于 2012-07-18T07:27:51.847 に答える