我尝试使用下面的MySQL语句获取行:分离从选择查询的输出结果按主键
+-----------------+
| text | b_id |
+-----------------|
| a | 1 |
| b | 1 |
| c | 1 |
| e | 2 |
| f | 2 |
我想在下面的格式来获取数据:
+---------------+
| b_id | Text |
+-------+-------+
| 1 | a,b,c |
| 2 | e,f |
我使用像下面的java/mysql api,但它给我的结果是任何b_id一个接一个,如何按照我的要求进行隔离,任何提示都会有用。
Connection conn = new SqlServiceImpl().getConnection("hostName/dbName?",
"user", "pwd", "");
String query =
"select desc.text,desc.b_id from desc,(select b_id,short_desc from bids where product_id=999) as bi where bi.b_id= desc.bug_id LIMIT 50;";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while (rs.next())
{
int id = rs.getInt("b_id");
String firstName = rs.getString("text");
System.out.format("%s, %s\n", id, firstName);
}
谢谢你的指针,但我只得到1行,但我已经使用GROUP BY末B_ID ...... – Anand
运行后,“工作SET SESSION group_concat_max_len = 18446744073709551615; “ – Anand