0

我使用 Mysql 和 spring data jpa

我对如何在某些列中查找缺失数据有疑问

该列属性是int。

所以。如果我在某些数据列中插入一些数据。

数字表

seq | number | sometext | someData | something | some | some

当我插入这样的数据时。

1 0 sometext someData  something some some,

2 2 sometext someData  something some some,

3 3 sometext someData  something some some,

4 5 sometext someData  something some some,

5 10 sometext someData  something some some,

如何让我缺少数字列

在 spring data jpa 本机查询中。

4

1 回答 1

1

这个查询怎么样

SELECT   CONCAT(X.EXPECTED, IF(X.GOT-1>X.EXPECTED, CONCAT(' ~ ',X.GOT-1), '')) AS MISSING
FROM     (
         SELECT
                  @ROWNUM:=@ROWNUM+1 AS EXPECTED,
                  IF(@ROWNUM=B.number , 0, @ROWNUM:=B.number ) AS GOT
         FROM     (SELECT @ROWNUM:=0) AS A
                  INNER JOIN YOUR_TABELE B
         ORDER BY B.number 
         ) AS X
WHERE X.GOT!=0;
于 2019-08-23T01:12:25.170 回答