SELECT all Values from a row with distinct values from a column
id | order_id |跟踪 |状态 |更新时间
表名:ndc
1 100204835 124124304 0 2017-06-29 00:00:00
2 100204874 124104482 0 2017-06-29 00:00:00
3 100204835 124124304 0 2017-06-29 00:00:00
我需要从 ndc 中选择所有值(id、order_id、tracking_no),其中 order_id 应该是唯一的,因为可能存在重复值。
The result should output all values in the row as I need to use them further.
例如。在上表中 order_id 100204835 是重复的。
- 在 SELECT 之后尝试 DISTINCT。示例:SELECT *, DISTINCT order_id FROM table
- 但这取决于您是否想要单行的数据,而不管第二行的第二个数据的重要性
试试这个:Select * from ndc group by order_id;
没有一个答案对我有用,所以这是我正在工作的一个。在 col4 上使用 group bu,同时获取其他列的最大值
QUERY:
1
|
SELECT id,order_id,tracking_no,status,update_time, DISTINCT order_id FROM ndc;
|
或者你可以使用简单的group by order_id;
语法:select * from table_name group by field_name;
NOTE: A DISTINCT and GROUP BY usually generate the same query plan, so performance should be the same across both query constructs.
- 不,这甚至列出了重复的记录。
您需要将 DISTINCT 与字段名称一起使用并指定其他字段。
SQL:SELECT DISTINCT order_id, id,tracking,status,update_time FROM table
更多大陆答案请关注-
MySQL – 选择所有列,其中一列是 DISTINCT
SELECT DISTINCT order_id,id,tracking_no FROM ndc;
also you can use it for distinct on multiple column
1
2 3 4 5 |
SELECT DISTINCT order_id FROM ndc
UNION SELECT DISTINCT id FROM ndc UNION SELECT DISTINCT tracking_no FROM ndc |
使用这个
1
|
Select * from table group by order_id;
|
- 这不起作用!如果它们是两个相同的 order_id,它会列出 2 行
来源:https://www.codenong.com/44822453/