sách gpt4 ăn đã đi

php - 包含计数的 4 路 SQL 查询

In lại Tác giả: Walker 123 更新时间:2023-11-30 01:03:17 27 4
mua khóa gpt4 giày nike

我有 4 张 table :

  1. ad (id, ...)
  2. website (id, title, URL, ...)
  3. space (id, website_id, ...)
  4. ad_space_counter (id, ad_id, website_id, space_id, impression_counter, click_counter)

一个网站可能分配有 2 或 3 个空间。

现在我希望实现的是进行一次选择并获得以下结果:

  1. ad_id
  2. website_id
  3. URL (from website table)
  4. title (from website table)
  5. impression_counter (but the TOTAL of all spaces assigned to that specific website_id)
  6. click_counter (but the TOTAL of all spaces assigned to that specific website_id)

因此,如果我们有 ad_id =1 和 website_id = 1,但有 3 个空格且 website_id = 1,那么 ad_space_counter 将生成 3 个条目,每个条目都有自己的特定展示次数和点击计数器。此 SELECT 必须获取所有这些的总和并将其显示在一个结果中。

Cảm ơn.

câu trả lời hay nhất

请尝试使用以下内容,请注意“ad_id”列未包含在列列表中。因此下面的查询可以被视为网站的统计数据。

lựa chọn 
a.website_id,
website.url,
website.title,
sum(a.impression_counter) as impression_counter,
sum(a.click_counter) as click_counter
from ad_space_counter a,
ad,
website
space
where ad.id = a.ad_id
and website.id = a.website_id
and space.id = a.space_id
nhóm theo
a.website_id,
website.url,
website.title

关于php - 包含计数的 4 路 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19907718/

27 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress