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
Mysql 选择除-1之外的其他值,并且该值与负值不同_Mysql - Fatal编程技术网

Mysql 选择除-1之外的其他值,并且该值与负值不同

Mysql 选择除-1之外的其他值,并且该值与负值不同,mysql,Mysql,不要选择以下选项: -非-1 -如果有带负号的相同正负值-例如,在本表中为45,负值为45,以此类推 你好,我有这张桌子。如果我想得到这个,我应该如何写查询 ID| uid | val1 | val2 --------------------- 1 | 80 | -1 | -1 2 | 81 | 45 | -1 3 | 82 | 99 | -1 4 | 81 | -45 | -1 5 | 82 | 99 | 50 6 | 83 | 55 | 70 7 | 83 | -55 | -70

不要选择以下选项: -非-1 -如果有带负号的相同正负值-例如,在本表中为45,负值为45,以此类推

你好,我有这张桌子。如果我想得到这个,我应该如何写查询

ID| uid | val1 | val2
---------------------
1 | 80 | -1  | -1 
2 | 81 | 45  | -1
3 | 82 | 99  | -1
4 | 81 | -45 | -1
5 | 82 | 99  | 50
6 | 83 | 55  | 70
7 | 83 | -55 | -70
8 | 81 | 41  | -1
9 | 83 | -1  | 80

像这样的东西能满足你的需要吗

[1]
  uid=81
  val1=41
  val2=

[2]
  uid=82
  val1=99
  val2=50

[3]
  uid=83
  val1=
  val2=80

我认为该键不存在,无法筛选出负对行。

@GordonLinoff此评论是否仍然有效?你的回答如下。@kermit。我想我找到了一个合理的解释。然而,OP并没有对答案做出回应,所以我不能说我真的理解它。
select t.*
from table t
where val1 <> -1 and val2 <> -1 and
      not exists (select 1
                  from table t2
                  where (t.val1 = -1 or t2.val1 = - t.val1) and
                        (t.val2 = -1 or t2.val2 = - t.val2)
                 );