开发者

SQLite3 joining rows to form a single row

开发者 https://www.devze.com 2023-02-21 04:01 出处:网络
I am building an android application which queries a database for a bus number, and bus departure time.

I am building an android application which queries a database for a bus number, and bus departure time.

The tables are thus -

Table 1: Route - _id, routenumber

Table 2: Routetimedetails - _id, routetime, routeid

My current query is this

select routenumber, route._id, routetime from route, routetimedata where route._id = 2 and routeid = route._id

and the result shows up like this >

routenumber | route._id | routetime
-------------------------------------
BIAS10      | 2         | 0945

BIAS10      | 2         | 1810

BIAS10      | 2         | 1945

BIAS10      | 2         | 0710
开发者_运维知识库

is there a way in sqlite3 to show the result in a single column like this -

BIAS10      | 2         | 0710, 0945, 1810, 1945

Thanks Mukul


I find that the Group_Concat() function does this easily

select routenumber, route._id, Group_concat(routetime) from route, routetimedata where route._id = 2 and routeid = route._id

0

精彩评论

暂无评论...
验证码 换一张
取 消