关于 php:SELECT all Values from a row with distinct values from a column | 珊瑚贝

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,同时获取其他列的最大值

1
2
3
4
5
select max(col1) as col1,max(col2) as col2,max(col3) as col3
  , col4
  from
    table1
  group by col4

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/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_10060.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?