Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从bash脚本中找到重复的mysql id集_Mysql_Sql_Bash_Duplicate Removal - Fatal编程技术网

如何从bash脚本中找到重复的mysql id集

如何从bash脚本中找到重复的mysql id集,mysql,sql,bash,duplicate-removal,Mysql,Sql,Bash,Duplicate Removal,我在这里的目标是显示任何包含完全相同的产品集的组UID。因此,组uid 5206和5485将最终显示,而1885不会显示,因为它没有相同的产品uid集。我必须通过bash脚本来实现这一点,因为我没有能力在MySQL 3.23.58中实现这一点(是的,它太旧了,我讨厌它,但不是我的选择)。我试图将表、组和产品存储在一个数组中,然后比较每个组的uid,看看它们是否包含相同的产品uid。谢谢你的帮助 您如何显示上面的表格 你可能会在小组讨论中取得一些成功 选择组uid、组CONCAT(产品uid、分隔

我在这里的目标是显示任何包含完全相同的产品集的组UID。因此,组uid 5206和5485将最终显示,而1885不会显示,因为它没有相同的产品uid集。我必须通过bash脚本来实现这一点,因为我没有能力在MySQL 3.23.58中实现这一点(是的,它太旧了,我讨厌它,但不是我的选择)。我试图将表、组和产品存储在一个数组中,然后比较每个组的uid,看看它们是否包含相同的产品uid。谢谢你的帮助

您如何显示上面的表格

你可能会在小组讨论中取得一些成功

选择组uid、组CONCAT(产品uid、分隔符',')、计数(*)
从…起
分组
计数(*)大于1的

我不确定它将如何对字符串排序,因为我目前没有mysql

SELECT group_uid, GROUP_CONCAT(product_uid,separator ','), count(*)
FROM <tab>
GROUP BY group_uid
HAVING count(*) > 1
如果您知道您感兴趣的是哪一组产品ID,您可以将其传入:

184 523 :5206 5485 
184 184 :1885 

不幸的是,group_concat不在mysql 3.23.58中。为了在mysql中实现这一点,我已经彻底搜索了我的选项,但我不能。它必须通过bash脚本完成。但是感谢您建议删除对
bash
的引用,因为这是一个SQL问题。Burhan,这是关于从bash脚本读取mysql结果的。我的问题纯粹是关于写一个bash脚本。Walker,你为什么不编辑这个问题并澄清它,不要在标题中添加
bash
,而是使用标记系统。谢谢。我得试试这个,看看能得到什么结果
awk '
    NR > 3 && NF == 7 {
        prod[$4] = prod[$4] $6 " "
    } 
    END {
        for (group in prod) 
            groups[prod[group]] = groups[prod[group]] group " "
        for (key in groups) 
            print key ":" groups[key]
    }
' mysql.out 
184 523 :5206 5485 
184 184 :1885 
awk -v prod_ids="184 523" '
    NR > 3 && NF == 7 {
        prod[$4] = prod[$4] $6 " "
    } 
    END {
        for (group in prod) 
            groups[prod[group]] = groups[prod[group]] group " "
        key = prod_ids " "
        if (key in groups)
            print groups[key]
    }
' mysql.out 
5206 5485