2017-05-04 78 views
0

我正在研究用于文本管理的应用程序。有许多不同语言的短文本,需要适合具有给定宽度(px)和行数的文本区域。我们的目标是找到所有不使用可用线宽的文本,并将其显示给用户进行编辑。
示例: enter image description here 在左侧文本中,每行仅占用可用空间的四分之一,这很糟糕。右边的文字是可以的。根据其他值查找值的SQL查询

我有这个表lengthcheckresult它看起来像这样左例如

id, idText, lineorder, usedspace, availablespace 
3 87  1   111  430 
4 87  2   116  430 
5 87  3   171  430 
6 87  4   120  430 

和喜欢本作的正确的榜样:

id, idText, lineorder, usedspace, availablespace 
3 87  1   408  430 
4 87  2   120  430 
5 87  3   0  430 
6 87  4   0  430 

所以我需要一个SQL查询其查找所有文本在后面跟着更多行时,行数少于可用空间的x%。你认为这是可能的吗?我不知道如何开始。

回答

1

使用这样的事情(作出有关表名等假设)

select 
    A.id 
--, (anything else you want) 
from dbname.dbo.tblname A 
where usedspace > 0 
    and availablespace > 0 -- Avoid divide by zero 
    and usedspace/availablespace < 0.5 -- Assume less than 50%? Pick your value. 
    and A.idText = 1234 -- The text of interest 
    and exists 
    (select B.id from dbname.dbo.tblname B 
    where B.idText = A.idText  -- Part of same text 
     and B.lineorder > A.lineorder -- Only later lines 
     and B.usedspace > 0   -- Only non-empty lines 
) 
-- order by etc, as required. 

此发现你作品的文本是不是任意比例较短(在这种情况下,50%),这也有如下文字不是空的。

+0

这很好,非常感谢你! – ondrums