希望有人可以帮助我解决这个问题。我有一个包含以下数据的表:
site_id type key data
2 organic-keywords-last-month (not provided) 9064
2 organic-keywords-last-month bmi 345
2 organic-keywords-last-month bmi kalkulator 445
2 organic-keywords-last-month grove pannekaker 678
2 organic-keywords-last-month grove vafler 976
2 organic-keywords-last-month lapper 475
2 organic-keywords-last-month melk.no 624
2 organic-keywords-last-month ostesuffle 361
2 organic-keywords-last-month scones 697
2 organic-keywords-last-month sunne pannekaker 658
2 organic-keywords-last-month sunne vafler 484
2 organic-keywords-this-month (not provided) 10034
2 organic-keywords-this-month bmi kalkulator 659
2 organic-keywords-this-month grove pannekaker 721
2 organic-keywords-this-month grove vafler 857
2 organic-keywords-this-month lapper 515
2 organic-keywords-this-month melk.no 587
2 organic-keywords-this-month ostesuffle 433
2 organic-keywords-this-month scones 626
2 organic-keywords-this-month smultringer 401
2 organic-keywords-this-month sunne pannekaker 566
2 organic-keywords-this-month sunne vafler 407
我想做的是查询本月的所有有机关键字,然后将它们加入到上个月的有机关键字中,这样我就可以得到本月 11 个关键字的列表,它们的表现和他们上个月的表现。
我正在使用以下查询:
SELECT
ktm.key AS keyword,
ktm.data AS `this month`,
klm.data AS `last month`
FROM
data AS ktm
LEFT JOIN data AS klm ON
(ktm.key = klm.key AND ktm.type = 'organic-keywords-this-month'
AND klm.type = 'organic-keywords-last-month')
WHERE
ktm.site_id = 2
AND klm.site_id = 2
ORDER BY
`this month` ASC
我认为应该返回 11 行,因为有 11 行类型为 'organic-keywords-this-month',但是当我运行它时它只返回 10 行,看起来更像是内部连接表而不是左连接.
有人有想法么?