sql:可选地分组多列

xwbd5t1u  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(257)

关闭。这个问题需要细节或清晰。它目前不接受答案。
**想改进这个问题吗?**通过编辑这个帖子来添加细节并澄清问题。

两年前关门了。
改进这个问题
我需要使用 group by 下表

id     ripped_file_name plate_length plate_width job_type_billing
665677 A                        23.5        26.0             1329
665678 A                        26.0        23.5             1329
665679 C                        26.0        23.5             1329
665680 D                        26.0        23.5             1329
665681 A                        26.0        23.5             1329
665682 A                        33.2        23.5             1329

Group by ripped_file_name,plate_width,plate_length 我想加一个箱子
where plate_width , plate_length can交换
预期结果

id     ripped_file_name plate_length plate_width job_type_billing
665681 A                        23.5        26.0             1329
665679 C                        26.0        23.5             1329
665680 D                        26.0        23.5             1329
665682 A                        33.2        23.5             1329

所以在第一排,第二排和第五排是分组的。

eeq64g8w

eeq64g8w1#

根据@strawberry的建议,您可以将较小的度量值(长度或宽度)粘贴在结果集中的一列中,将较大的度量值粘贴在另一列中。然后按这两个派生列分组:

SELECT 
    ripped_file_name, 
    LEAST(plate_length,plate_width) as measure1, 
    GREATEST(plate_length,plate_width) AS measure2
FROM yourtable
GROUP BY ripped_file_name, measure1, measure2

相关问题