mysql中有如下表temp
id
------------
aaa
bbb
ccc
怎么写一个sql语句 查询后得到如下结果,类似笛卡尔积
id
------------
aaaaaa
aaabbb
aaaccc
bbbaaa
bbbbbb
bbbccc
cccaaa
cccbbb
cccccc
多谢各位!!
------解决方案--------------------
select a.id||b.id
from temp a,temp b
------解决方案--------------------
select a.*,b.*, a.fname || b.fname from (
select 'aaa' as fname from dual
union all
select 'bbb' from dual
union all
select 'ccc' from dual
) a,
(
select 'aaa' as fname from dual
union all
select 'bbb' from dual
union all
select 'ccc' from dual
) b
FNAME FNAME A.FNAME||B.FNAME
----- ----- ----------------
aaa aaa aaaaaa
aaa bbb aaabbb
aaa ccc aaaccc
bbb aaa bbbaaa
bbb bbb bbbbbb
bbb ccc bbbccc
ccc aaa cccaaa
ccc bbb cccbbb
ccc ccc cccccc
------解决方案--------------------
用如下语句可以实现。
SELECT CONCAT(tt.id,tt.id1) FROM (SELECT a.id,b.id AS id1 FROM temp a,temp b )AS tt