如何在SQL case语句中选择2个值?

时间:2015-02-27 13:33:38

标签: sql sqlite

考虑这个问题:

SELECT CASE 
    WHEN identifier = 'V' THEN pos_x, pos_y 
    WHEN identifier = 'D' THEN height, weight
END 
FROM sprite_data;

这会产生错误,因为(我如何理解)case语句只能返回一个值,但我试图返回2个值(pos_x和pos_y OR高度和宽度)。如何使case语句返回两个值?

2 个答案:

答案 0 :(得分:1)

你不能让一个案例返回两个值。你可以这样做:

SELECT CASE 
    WHEN identifier = 'V' THEN pos_x    
    WHEN identifier = 'D' THEN height
END AS x,
CASE 
    WHEN identifier = 'V' THEN pos_y   
    WHEN identifier = 'D' THEN weight
END AS y
FROM sprite_data;

答案 1 :(得分:-1)

您可以在sqlite中使用printf

未经测试:

printf ('%s, %s', pos_x, pos_y) as pos_xy