我已将大型CSV文件导入表格。该表的样本如下所示
name, eye,point,field,date,seconds,sensitivity*10,slope,intercept,T*1000
NESSA SONIA ,R,6,4,08-04-09,32658845,160,1.062300e+001,62538, 1282
NESSA SONIA ,R,6,5,20-05-09,36288632,20, 5.360101e+000,64036, 771
NESSA SONIA ,R,6,6,02-12-09,53223062,60, 3.425260e+000,64590, 767
NESSA SONIA ,L,6,4,08-04-09,32658922,230,4.629489e+000,64382, 582
NESSA SONIA ,L,6,5,20-05-09,36288515,170,2.805373e+000,64901, 511
NESSA SONIA ,L,6,6,02-12-09,53223059,220,3.528252e+000,64694, 1022
我必须比较右眼和左眼"敏感度* 10"值,匹配点和字段值并提取最高(我的意思是行)。
例如,我必须比较第一行和第四行作为点,字段和日期相同,并提取第四行,因为灵敏度最高。我有一个巨大的文件,需要提取所有值。任何人都可以帮助sql查询,将非常感谢。
答案 0 :(得分:1)
(select `table l`.* from `table l`, `table r`
where `table l`. `sensitivity*10` > 10 and `table l`.`sensitivity*10`>`table r`.`sensitivity*10`)
union
(select `table r`.* from `table r`, `table l`
where `table r`. `sensitivity*10` > 10 and `table r`.`sensitivity*10`>`table l`.`sensitivity*10`)
答案 1 :(得分:0)
您需要使用SQL MAX()
函数和GROUP BY
名称。
尝试这样的事情:
SELECT *
FROM (
SELECT point, field, MAX(sensitivty*10) AS max
FROM table
GROUP BY
name
) tbl
JOIN table
ON table.point = tbl.field
另外,请查看其他Stackoverflow问答,其中包含与您感兴趣的查询类似的查询:SQL Group by & Max
答案 2 :(得分:0)
我认为这应该适合你:
select if(t1.sensitivity*10 > t2.sensitivity*10,t1.sensitivity*10,t2.sensitivity*10) as col1
from table t1
inner join table t2
on t1.field = t2.field
and t1.point = t2.point
and t1.date = t2.date
where t1.eye ='R' and t2.eye ='L'