简体   繁体   English

如何选择具有相同值的所有列值的行?

[英]How can I select rows with all Column value, which have the same values?

I am trying to get all the courID values that have same memid values, For example, if my table looked like this (as shown in image):我正在尝试获取所有具有相同 memid 值的 courID 值,例如,如果我的表看起来像这样(如图所示):
在此处输入图片说明

SELECT 
  memId, GROUP_CONCAT(courId) 
FROM table_name 
GROUP BY memId

Let assuming you have created you table like shown below假设您已经创建了如下所示的表

CREATE TABLE test (
  MemId INTEGER,
  CourId VARCHAR (50)
);

and executing insert like shown below并执行如下所示的插入

INSERT INTO test VALUES (1, '2');
INSERT INTO test VALUES (1, '3');
INSERT INTO test VALUES (2, '2');
INSERT INTO test VALUES (3, '1');
INSERT INTO test VALUES (3, '3'); 

Run query like so像这样运行查询

SELECT MemId, GROUP_CONCAT( CourId) FROM test GROUP BY MemId

Your result should look like this你的结果应该是这样的

| MemId | GROUP_CONCAT( CourId) |
|-------|-----------------------|
|     1 |                   2,3 |
|     2 |                     2 |
|     3 |                   1,3 |

for further reading and understanding see this link如需进一步阅读和理解, 请参阅此链接

暂无
暂无

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

相关问题 如何选择不同的行,其中一列可能具有许多相同的值,但所有第二列均具有相同的值? - How do I select distinct rows where a column may have a number of the same values but all their 2nd columns have the same value? SQL-如何选择列中具有value1但同一列中没有value2的所有行? - SQL - how to select all rows which have value1 in column but not value2 in same column? 如何检查所有行是否具有相同的列值? - How can I check if all rows have the same column value? 如何创建一个新列来保存具有相同值的所有行的所有主键值? - How do I create a new column that holds all the primary key values of all rows that have the same value? 如何为列的相同值选择所有行? - How to select all rows for same value of column? 如何选择两列中具有相同值集的行,从而将第三列中的值连接起来? - How to select rows which have same set of values in two columns and hence concatenate the values in the third column? SQL仅选择具有相同列值的行 - SQL select only rows which have same column value 我想 select 行在列中具有特定值但列可以包含多个值 - I want to select rows which has a particular value in the column but the column can contain multiple values 如何选择具有相同值的所有行 - How to select all rows which have identical values 如何根据我没有的列值选择行,但是我与列值存在于同一行? - How to select rows based on a column value I don't have, but that exists in the same row as a column value I do have?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM