I have huge pageview level table, where each session has multiple pageviews. Session -> Pageviews – 1 : M From the pageviews table, I need to consolidate the data into one row per session with meta data like FirstPageview, LastPageview, #ofvisitstoLogin Firstpageview is defined as the very first page…
SQL: How can I pick a cell value from one table as a condition to select another table
Hi I’m a new learner of SQL. How can I realize this process in SQL or perhaps with python if needed: First, from table1, I randomly selected two results: I need to use the value x and y as conditions to display another table. For instance, using x, I can: What I need is to get the length of table2
Array to string with Django and MySQL
I need to design SQL query in html on Django I have an array in my table like : When I call this array in my page : I have : [‘aa’, ‘bb’, ‘cc’] What do I do if I want : a b c I tried with .split(‘,’) but I’ve already ‘[]’ I tried with for item …
Why am I getting a cross-reference error with my insert/select statement in single database
I have the following INSERT statement, and it works fine without the WHERE clause, but will not work with it. There is a separate database that I have connected to via a dblink connection, and I have created several views that contain data I will need for the database I’m working in. I have the followin…
Combine lead and lag function without overlap
I have this table: I need to get an output like this: I’ve tried a normal lead window function, but that would only show the first ‘Creation’ and not that last ‘Pending’ that I need. Answer Your table has N records (3 in the example provided) when query must return N + 1 (4); let…
Renumbering A Column Based On Other Columns
This table contains Purchase Orders which can have multiple lines per order. Right now the table appears like this. Purchase_OrderNumber Account_Number Line_Number 174558 0000448 1 174558 0000448 2 175812 295812 1 175812 295812 1 175812 295812 2 175812 295812 545 175812 295812 26686 175812 295812 53481 175813…
How to select max and min of 1 column based on other 2 columns?
I’m trying to get the max and min date values in column C based on the (column A, column B) unique pair combinations. Suppose I have a table like: The output I want to get is: My attempt query has been taking 20 mins to run with no output yet (just tried to get max date from column C for
How to calculate Total transactions amount column with input / output type?
I have two tables : (transactions and Accounts) their columns are as shown in the picture bellow: the Accounts table is simple just two columns ID and account name. The important columns in the Transactions table are Amount and type, the type indicates whether the transaction is an input to the account or an …
Finding orders placed between two times gives zero result
I’m not sure what’s happening here. I’m trying to select the orders that were placed between 4PM and 4AM, so from 1600 to 0400. The date does not matter, just the time. This is what I’ve tried so far. Here is the code for the table: I selected using several ways: I keep getting nothing…
How do I insert multiple records with an ON CONFLICT UPDATE clause in Postgres?
Given this table, which is just an example. I need to do an upsert on multiple records. payment_status returns as ambiguous. The problem I’m trying to solve here is that I have a process that imports data but if it encounters a conflict, it needs to update the current data with the new data. (it’s…