简体   繁体   English

从mysql中的多行获取单列

[英]get single column from multiple rows in mysql

i have two rows as show in below image.i want to get it as a single column based on aday(TUE) in the table,please any help me how to workout this. 我有两行,如下图所示。我想根据表中的day(TUE)将其作为一列,请帮助我如何进行锻炼。 thanks in advance 提前致谢

在此处输入图片说明在此处输入图片说明

You can't as that would give variable numbers of columns for the rows returned. 您不能那样为返回的行提供可变的列数。

You can do a fiddle with GROUP_CONCAT:- 您可以使用GROUP_CONCAT来摆弄:

SELECT doctorname, aday, GROUP_CONCAT(CONCAT_WS('~', availfrom, availupto) SEPARATOR '#') avail_time_slots
FROM sometable
GROUP BY doctname, aday

Then in code you would need to split up the avail_time_slots 然后,在代码中,您需要拆分avail_time_slots

This question isn't related to java, but rather SQL queries. 这个问题与Java不相关,而与SQL查询有关。 You could select all in a table, and only return rows where column aday has the value "TUE". 您可以选择表中的所有内容,并且仅返回每天列的值为“ TUE”的行。

SELECT * FROM table WHERE aday=TUE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM