[SQL ] MYSQL如何組合唯一化?
使用版本 MySQL 5.0.51
table1
id group1 name1 type1
1 A aaa Write
2 A bbb Report
3 A ccc Read
4 B ddd Write
5 B eee Read
6 B fff Report
7 C ggg Write
將他們組合出來看他們組合類型是如何
我的SQL
SELECT
a.type1 as Type1
, b.type1 as Type2
, count(*) as total
FROM `table1` a, `table1` b
WHERE a.group1=b.group1
AND a.name1 != b.name1
Group by a.type1
Order by 3
可是卻會輸出
Type1 Type2 Count
Write Report
Write Read
Read Write
Read Report
Report Read
Report Write
(下略)
類似這樣的結果
可是我想要的是
Type1 Type2
Write Report
Write Read
Report Read
意思是 (Write, Report) = (Report, Write)
這樣MySQL可以辦到嗎@@?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.165.78.122
討論串 (同標題文章)