简体   繁体   中英

SQLITE Is it possible to calculate the length of the longest increasing subsequence also referred to as sortation percent?

With the latest version of Sqlite, Is it possible to calculate the length of the longest increasing subsequence, also referred to as sortation percent, using a sqlite UDF, user defined function?

October 15,2012 edit as requested by @Code-Guru.

Following the project gurus's example sequence of -- 1,2,3,4,3,5,6,7,8,10 -- the numeric sorted ascending subsequence is found to be 1,2,3,4,5,6,7,8,10 using an automatic variable containing the most recent monotically increasing sequence member value and traversing the array sequentially. As a result, the length of the sorted numeric ascending subsequence is 9. The length of the entire sequence is 10. So, the sortation percentage is (9/10) * 100% = 90%. Thank you.

Sqlite does not have any functionality that implements longest increasing subsequence, so you will need a user defined function

You can sort by function results. I don't believe UDFs are treated any differently in this respect.

Here is an example of how you would use a function (user defined or not) to order your query results.

sqlite> create table foo(a);
sqlite> create table foobar(a);
sqlite> create table fubar(a);
sqlite> select name, length(name) as len from sqlite_master;
foo|3
foobar|6
fubar|5
sqlite> select name, length(name) as len from sqlite_master order by len;
foo|3
fubar|5
foobar|6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM