简体   繁体   English

SQLITE是否可以计算最长递增子序列的长度,也称为排序百分比?

[英]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? 使用最新版本的Sqlite,是否可以使用sqlite UDF用户定义函数来计算最长增长子序列的长度,也称为排序百分比?

October 15,2012 edit as requested by @Code-Guru. 2012年10月15日,按照@ 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. 按照项目专家的示例序列-1,2,3,4,3,5,6,7,8,10-发现数字排序的升序子序列为1,2,3,4,5,6 ,7,8,10,使用包含最新的按单调递增的序列成员值并顺序遍历数组的自动变量。 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%. 结果,排序后的数字升序子序列的长度为9。整个序列的长度为10。因此,排序百分比为(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 Sqlite没有实现最长的递增子序列的任何功能,因此您将需要一个用户定义的函数

You can sort by function results. 您可以按功能结果排序。 I don't believe UDFs are treated any differently in this respect. 我不认为UDF在这方面会有所不同。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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