[英]MySQL select rows where the JSON array column is a subset of another array
[英]How to select columns with subset of another column in mysql?
我有這個問題的復雜版本( 如何在mysql中選擇具有相同值集的列? )來處理。
在關系R(A,B,C)中,問題是要找出“具有4個或更多個常見B的A” 。 僅供參考:“ AB”是候選關鍵字。
我能做的就是這個
查詢:
select * from
(select A, group_concat (B separator ', ') all_b's from R group by A having
(count(B))>3) p1
join
(select A, group_concat (B separator ', ') all_b's from R group by A having
(count(B))>3) p2
on p1.all_b's = p2.all_b's and p1.A <> p2.A;
輸出:
Null Set
但是,答案應該是別的。 知道如何處理嗎?
樣本數據:
A B C
a1 b1 asdas
a1 b2 sdvsd
a1 b3 sdfs
a1 b4 evevr
a2 b1 jdjd
a2 b2 dkjlfnv
a2 b3 sdfs
a2 b4 evevr
a2 b5 adfgaf
a3 b1 sdfsdf
預期產量
A A count
a1 a2 4
應該是這樣的:
SELECT
first.A AS first_A,
second.A AS second_A,
COUNT(*) AS countSameBs
FROM
R first
JOIN
R second ON
first.B = second.B AND
first.A != second.A
GROUP BY
first_A, second_A
HAVING
countSameBs >= 4 AND
first_A < second_A
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.