我想在以下条件下从mysql数据库中获取记录
我有以下表格:
organization_ Table
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
Condtion作为organizationId ==?
所以基本上我想要广告系列广告列表,其中organization_id =?
注意:camapign表中的同一个adv_id应该有多个条目,ad_display中有多个条目的同一个camp_id
答案 0 :(得分: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 = ?;
答案 1 :(得分: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
答案 2 :(得分: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 = <?>
答案 3 :(得分: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 =? ;
答案 4 :(得分: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=?
答案 5 :(得分:-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;