recursive-query

Check if Table contains a value in lua

[亡魂溺海] 提交于 2020-12-12 12:14:30
问题 I am looking for a method to see if the value is in array (table) The example table has 3 entries, each entry containing a table with multiple entries Say I am checking if 'apple' is in 'data' data = { {"alpha","bravo","charlie","delta"}, {"apple","kiwi","banana","pear"}, {"carrot","brocoli","cabage","potatoe"} } This is the code I have, a recursive query. The problem is the function breaks somewhere as it drops the positive value local function hasValue(tbl, str) local f = false for ind, val

get parents and children of tree folder structure in my sql < 8 and no CTEs

自作多情 提交于 2020-11-30 11:08:58
问题 I have a folder table that joins to itself on an id , parent_id relationship: CREATE TABLE folders ( id int(10) unsigned NOT NULL AUTO_INCREMENT, title nvarchar(255) NOT NULL, parent_id int(10) unsigned DEFAULT NULL, PRIMARY KEY (id) ); INSERT INTO folders(id, title, parent_id) VALUES(1, 'root', null); INSERT INTO folders(id, title, parent_id) values(2, 'one', 1); INSERT INTO folders(id, title, parent_id) values(3, 'target', 2); INSERT INTO folders(id, title, parent_id) values(4, 'child one',

get parents and children of tree folder structure in my sql < 8 and no CTEs

心已入冬 提交于 2020-11-30 11:08:12
问题 I have a folder table that joins to itself on an id , parent_id relationship: CREATE TABLE folders ( id int(10) unsigned NOT NULL AUTO_INCREMENT, title nvarchar(255) NOT NULL, parent_id int(10) unsigned DEFAULT NULL, PRIMARY KEY (id) ); INSERT INTO folders(id, title, parent_id) VALUES(1, 'root', null); INSERT INTO folders(id, title, parent_id) values(2, 'one', 1); INSERT INTO folders(id, title, parent_id) values(3, 'target', 2); INSERT INTO folders(id, title, parent_id) values(4, 'child one',

a query to generate 5 random DNA sequences that are each about 20 bases, [duplicate]

♀尐吖头ヾ 提交于 2020-07-10 08:46:09
问题 This question already has answers here : Postgresql:Generate Sequence (2 answers) Closed 14 days ago . I got this query to solve for the first 20 but I don’t know how to extend that to the 5 rows prepare dna_length(int) as with t1 as ( select chr(65) as s union select chr(67) union select chr(71) union select chr(84) ) , t2 as ( select s, row_number() over() as rn from t1) , t3 as ( select generate_series(1,$1) as i, round(random() * 4 + 0.5) as rn ) , t4 as ( select t2.s from t2 join t3 on

Unexpected data at typical recursion

醉酒当歌 提交于 2020-06-29 03:53:08
问题 It's hard for me to use words to describe this, so here's the sample: select * into t from (values (10, 'A'), (25, 'B'), (30, 'C'), (45, 'D'), (52, 'E'), (61, 'F'), (61, 'G'), (61, 'H'), (79, 'I'), (82, 'J') ) v(userid, name) Notice how F,G and H have the same userid. Now, consider the following recursive query: with tn as ( select t.userId,t.name, row_number() over (order by userid,newid()) as seqnum from t ), cte as ( select userId, name, seqnum as seqnum from tn where seqnum = 1 union all

How can I parse delimited list in string to rows?

我们两清 提交于 2020-06-17 06:21:48
问题 This is my previous question: How can I merge two strings of comma-separated numbers in MySQL? I tried to use delimited list with these reasons: the data is more than 2000 rows. I have just one day. this is not production level I need to parse the data with my hands. I thought I don't have any choice. But I found this: SQL split values to multiple rows So, I got some hopes from it. But it's quite difficult to apply it to my table. Mine is different form. I have multiple columns and I'd like

How can I parse delimited list in string to rows?

旧城冷巷雨未停 提交于 2020-06-17 06:21:16
问题 This is my previous question: How can I merge two strings of comma-separated numbers in MySQL? I tried to use delimited list with these reasons: the data is more than 2000 rows. I have just one day. this is not production level I need to parse the data with my hands. I thought I don't have any choice. But I found this: SQL split values to multiple rows So, I got some hopes from it. But it's quite difficult to apply it to my table. Mine is different form. I have multiple columns and I'd like