如何过滤MySQL数据库中的项目列表?

时间:2021-01-06 11:14:48

I have list store in mysql table file1=(1,2,3,4,6,7) and other list file2 = (3,2,4,8,9,10,12) is not stored in table, i want compare both and result should be like result=(6,7,8,9,10,12) then calculate the percentage. like 100*(result/file1+file2) in mysql data structure. i do not know how i will do it. please know body know guide me or give me a small example. thanks

我在mysql表file1 =(1,2,3,4,6,7)列表存储,其他列表file2 =(3,2,4,8,9,10,12)没有存储在表中,我想要比较两者和结果应该像result =(6,7,8,9,10,12)然后计算百分比。像mysql数据结构中的100 *(result / file1 + file2)。我不知道我会怎么做。请知道身体知道指导我或给我一个小例子。谢谢

2 个解决方案

#1


1  

Create a temporary table to store the "other" list that is not already in a table, and then use a join or union to get the result you want.

创建一个临时表来存储表中尚未存在的“其他”列表,然后使用连接或联合来获得所需的结果。

If you are wanting to select the values that are not in either list, then you can use GROUP BY and COUNT to count the occurrence of each number, and then HAVING to select those rows with a count of 1.

如果要选择不在任一列表中的值,则可以使用GROUP BY和COUNT计算每个数字的出现次数,然后HAVING选择计数为1的那些行。

#2


0  

I don't think you can easily do that in pure sql. you need a procedural language to get the result in the first list, merge, sort, unique with the second list and compute the result.

我不认为你可以在纯sql中轻松做到这一点。你需要一个过程语言来获得第一个列表中的结果,合并,排序,与第二个列表唯一并计算结果。

#1


1  

Create a temporary table to store the "other" list that is not already in a table, and then use a join or union to get the result you want.

创建一个临时表来存储表中尚未存在的“其他”列表,然后使用连接或联合来获得所需的结果。

If you are wanting to select the values that are not in either list, then you can use GROUP BY and COUNT to count the occurrence of each number, and then HAVING to select those rows with a count of 1.

如果要选择不在任一列表中的值,则可以使用GROUP BY和COUNT计算每个数字的出现次数,然后HAVING选择计数为1的那些行。

#2


0  

I don't think you can easily do that in pure sql. you need a procedural language to get the result in the first list, merge, sort, unique with the second list and compute the result.

我不认为你可以在纯sql中轻松做到这一点。你需要一个过程语言来获得第一个列表中的结果,合并,排序,与第二个列表唯一并计算结果。