ios SQLite - 选择一列的 DISTINCT 并获取其他列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17277152/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQLite - SELECT DISTINCT of one column and get the others
提问by javiazo
I have a table like this (but with more columns):
我有一个这样的表(但有更多的列):
Code Quantity
----- --------
00001 1
00002 1
00002 1
00002 2
00003 2
00003 1
And I want to get the same result that with SELECT DISTINCT Code FROM table
(00001,00002,00003) but with all of the other table columns.
我想获得与SELECT DISTINCT Code FROM table
(00001,00002,00003)相同的结果,但与所有其他表列相同。
UPDATED:
If I perform this: SELECT DISTINCT Code, Quantity from table
I get:
更新:如果我执行这个:SELECT DISTINCT Code, Quantity from table
我得到:
Code Quantity
----- --------
00001 1
00002 1
00002 2
00003 1
00003 2
And I would like to get:
我想得到:
Code Quantity
----- --------
00001 1
00002 1
00003 1
Thanks in advance!
提前致谢!
回答by Gordon Linoff
Assuming you are using MySQL (as the question is tagged), the following will return an arbitrary value for the other columns:
假设您正在使用 MySQL(因为问题已标记),以下内容将为其他列返回任意值:
select *
from t
group by code;
However, the particular values being selected come from indeterminate rows.
但是,选择的特定值来自不确定的行。