5

我想在以下条件下从 mysql 数据库中获取记录

我有以下表格:

  • 组织_表

    organizationId | organizationname
    
  • 竞选表

    camp_id | camp_name | adv_id | organizationId
    
  • 广告表

    adv_id | adv_name
    
  • ad_display 表

    ad_displayId | adv_id | camp_id |
    

现在从 ad_display 表中我想获取这样的记录:

| adv_name | camp_name | organizationname

WHERE条件为 where organizationId == ?

所以基本上我想要organization_id =的广告系列的广告列表?

注意:在 camapign 表中应该有相同 adv_id 的多个条目,并且在 ad_display 中应该有多个条目的相同 camp_id

4

6 回答 6

7

试试这个:

SELECT ad.ad_displayId, a.adv_name, c.camp_name, o.organizationname 
FROM ad_display ad 
INNER JOIN advertise a ON ad.adv_id = a.adv_id 
INNER JOIN campaign c ON ad.camp_id = c.camp_id 
INNER JOIN organization o ON c.organizationId = o.organizationId 
WHERE o.organizationId = ?;
于 2012-12-28T09:42:44.410 回答
2

也许是这样的?

SELECT Distinct
  advertise.adv_name,
  campaign.camp_name,
  organization_.organizationname
FROM
  advertise inner join campaign
  on advertise.adv_id = campaign.adv_id
  inner join organization_
  on campaign.organizationID = organization_.organizationID
WHERE
  organization_.organizationID = 1
于 2012-12-28T09:41:05.987 回答
1
SELECT * FROM campaign
LEFT JOIN ad_display ON campaign.camp_id = ad_display.camp_id
LEFT JOIN advertise ON ad_display.adv_id = advertise.adv_id
WHERE campaign.organizationId = <?>
于 2012-12-28T09:41:46.483 回答
1

使用下面的代码

SELECT dv_name,
       camp_name,
       organizationname
FROM   organization
       inner join campaign
               ON organization.organizationid == campaign.organizationid
       left join advertise
              ON campaign.adv_id == advertise.adv_id
WHERE  condition =? ; 
于 2012-12-28T09:44:37.140 回答
1
SELECT  advertise.adv_name, 
        campaign.camp_name, 
        organization_Table.organizationname
FROM   ad_display 
    INNER JOIN advertise ON ad_display.adv_id = advertise.adv_id 
    INNER JOIN campaign ON ad_display.camp_id = campaign.camp_id 
    INNER JOIN organization_ Table ON campaign.organizationId = organization_Table.organizationId
    AND organization_Table.organizationId=?
于 2012-12-28T09:53:06.353 回答
-1
SELECT batch_number,
       Count(receipt_number) AS tot_rec,
       Sum(amount)           AS tot_amount
FROM   receipt_header
GROUP  BY batch_number
UNION ALL
SELECT batch_number,
       Count(receipt_lines.receipt_number),
       Sum(receipt_lines.amount)
FROM   receipt_lines
       INNER JOIN receipt_header
               ON receipt_header.record_id = receipt_lines.header_record_id
GROUP  BY batch_number
ORDER  BY batch_number ASC; 
于 2015-09-19T07:03:03.607 回答