Recursive query in tree MySQL8 / MariaDB10

Tags: , ,


I have a tree-like structure for categories on my database: create table cat( id int auto_increment primary key, url varchar(50), parent int references cat(id) ) How can i build the ...

Tags: sql

Distinct IDs from one table for inner join SQL

Tags:


I'm trying to take the distinct IDs that appear in table a, filter table b for only these distinct IDs from table a, and present the remaining columns from b. I've tried: SELECT * FROM ( SELECT ...

execute multiple create view statements in snowflake

Tags: ,


Is there a way to create multiple views in one query in Snowflake? I keep getting error when I try this - create or replace view forecast_view as select * from forecast where variable = 'Name' go ...

SQL Query with criteria of 6 chars and wildcards

Tags: , ,


I'm stuck with an SQL query to get what I need. My input is this: COD SINOM A 123456 B 987654, 123456, 111111 C 123456 , 234501 D 9912345699 E 99123456, 789012 F 77123456 Both fields are ...

Tags: mariadb sql

SQL, operation between paired rows

Tags: ,


I have a table t1 a b 1 4 2 2 3 9 2 1 1 6 3 7 I need the output a result 1 4*6 2 2*1 3 9*7 I have been able to do it in a far from efficient way and would like a more ...

Efficient Multiple Group-bys

Tags: ,


I have the following table: Year Week Day_1 Day_2 Day_3 2020 1 Walk Jump Swim 2020 3 Walk Swim Walk 2020 1 Jump Walk Swim I want to group by YEAR, WEEK and Event (Walk, jump, Swim) and count the ...

SQL to get 3 adjacent actions without duplicate from the flags

Tags: , , , ,


I have a question that a little bit similar with question#66044663 but more complicated. Here's my dummy data. I want to get 3 adjacent actions(no duplicate) from the flag by each user. Here's the ...

Tags: sql tsql

Is there a way of getting a proportional section of an SQL table?

Tags: ,


I'm trying to split a single query into 4 parts, for readability purposes. Having it as a single query, while adequate, isn't "pretty" for display purposes. An example would be a query that ...

Tags: sql sqlite

How to combine multiple sqlite queries into one line

Tags: ,


Sorry if this question is dumb. i am a beginner and for the past hour i'v been searching the internet for answer and i haven't found one(maybe because i am bad at searching). Anyway, i am writing a ...

Keyword IF not expected

Tags: , ,


I have the following inline SQL code, running on an AS400. The IF comes up as unexpected but I don't understand why. What I'm trying to do is to build a stored procedure to update, or insert, a ...