简体   繁体   English

使用group_concat获取多行的mysql结果

[英]Get mysql result of multiple rows in one with group_concat

I have a table which has a column id and a column isadmin .我有一个表,它有一个列id和一个列isadmin

I want to execute this query, which works just fine:我想执行这个查询,它工作得很好:

SELECT id FROM mytable WHERE isadmin = TRUE;

But instead of getting multiple rows I would like to get one row in csv format.但是我不想获得多行,而是想获得 csv 格式的一行。 I found this link and created the following query, which does not work, I get a MySQL error:我找到了这个链接并创建了以下查询,但它不起作用,我收到一个 MySQL 错误:

SELECT GROUP_CONCAT(id SEPERATOR ',') FROM mytable WHERE isadmin = TRUE;

The error message is:错误信息是:

You have an error in your SQL syntax;您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SEPERATOR ', ') FROM mytable WHERE isadmin = TRUE' at line 1检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“SEPERATOR”、“) FROM mytable WHERE isadmin = TRUE”附近使用正确的语法

If this is not enough information just tell me and I will provide them.如果这还不够,请告诉我,我会提供给他们。

The comma is the defaul separator so you don't need逗号是默认分隔符,所以你不需要

 SELECT GROUP_CONCAT(id ) FROM mytable WHERE isadmin = TRUE;

anyway is separator and nt seperator无论如何是分隔符和nt分隔符

SELECT GROUP_CONCAT(id SEPARATOR ',') FROM mytable WHERE isadmin = TRUE;

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

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