2017-05-04 50 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