我有以下查询:
SELECT word, count
FROM t_word t
JOIN t_counter tc
ON t.word_id = tc.id
产生类似的东西:
'cab', 2
'capital', 3
'new york', 2
我想做的是将结果显示如下:
'cab',
'cab'
'capital',
'capital',
'capital',
'new york',
'new york'
因此count列实际上会为我的查询复制该行。我不完全确定这是否可行,因为我在MySQL中没有玩过很多循环...任何指导都非常感谢!
答案 0 :(得分:1)
Select T.word
From t_word As T
Join (
Select 1 As Num
Union All Select 2
Union All Select 3
) As Numbers
On Numbers.Num <= T.count
如果count
实际上来自counter
表,那么您可以执行以下操作:
Select T.word
From t_word As T
Join t_counter As TC
On TC.id = t.word_id
Join (
Select 1 As Num
Union All Select 2
Union All Select 3
) As Numbers
On Numbers.Num <= TC.count