我有两张表如下:
表xyz
id url
-- -------------
1 someweb.com/1
2 example.com
3 abc.com
表abc
id url
-- -----------
1 example.com
我期待输出为:
id url count
-- ----------- -----
1 example.com 2
2 abc 1
我执行此查询:
SELECT DISTINCT
xyz.url,
COUNT(xyz.url) as count
from abc
LEFT JOIN xyz
on abc.id = substring_index(xyz.url, '/someweb.com/', -1)
因为某些链接位于abc
表中,该表链接为xyz
字符串。
知道怎么做吗?
答案 0 :(得分:0)
试试这个
SELECT
count(*) AS count,
u.url
FROM
(
SELECT
*
FROM
xyz
UNION ALL
SELECT
*
FROM
abc
) AS u
GROUP BY
u.url