期望输出 | |||
---|---|---|---|
q1 | count1 | q2 | count2 |
B | 2 | B | 1 |
D | 1 | C | 2 |
只会差寻一列,求教如何查询多列数据重复个数!
PHP中文网2017-04-17 15:59:43
select distinct q1,t1.count1,tt.q2,tt.count2 ... from t
left join (select q1,count(1) count1 from t group by q1) t1 on t1.q1 = t.q1
full join (
select distinct q2,t2.count2 from t
left join (select q2,count(1) count1 from t group by q2) t2 on t2.q1 = t.q1
) tt on tt.q2 = t.q1 ...
感覺好粗鄙,等大神來。