Reputation: 1068
I have one table called 'answers' with four column wherein adding answers with positive and negative rankings and i want to retrieve answer with different aliasing for answer with positive ranks and answer with negative ranks. is there any way to retrieve same column with two different aliases ?
id answer rank question_id
1 Yes 1 1
2 No 2 1
3 True -2 2
4 False -1 2
I want to have this answers in the form of comma delimited list I have tried this but no success.
SELECT CASE WHEN a.rank > 0 THEN GROUP_CONCAT(a.answer) END AS answer,
CASE WHEN a.rank < 0 THEN GROUP_CONCAT(a.answer) END AS matrix
FROM answers a.
Upvotes: 0
Views: 224
Reputation: 3855
You can try following:
SELECT GROUP_CONCAT(IF(rank>0,answer,NULL)) as positive_ans, GROUP_CONCAT(IF(rank<0,answer,NULL)) as negative_ans FROM answers
Upvotes: 1
Reputation: 204904
select group_concat(case when rank > 0 then answer end) as pos_answers,
group_concat(case when rank < 0 then answer end) as neg_answers
from answers
Upvotes: 1