Skip to content
Advertisement

Expanding jsob array in PostgreSQL to produce analytics

Imagine that we have the following table using jsonb on PostgreSQL: And the following data is available: Is it possible to expand the JSON array to 2 columns similarly to what PowerBI expand does and get the following result? firstName surName bookName William Shakespeare Hamlet William Shakespeare Juliet Agatha Christie Hercule Poirot Agatha Christie Miss Marple instead of firstName surName

Nested SUM with OVER clause

I am trying to understand how nested SUMs with OVER clause work in SQL. Let’s say i have the following schema in my DB and suppose that i want to calculate the (number of deliveries of each region)/(number of deliveries of the state) on the same year. The query to do the calculation is: I can’t understand how the PARTITION

Interpolate Multiseries Data In SQL

I have a system that stores the data only when they are changed. So, the dataset looks like below. data_type_id data_value inserted_at 2 240 2022-01-19 17:20:52 1 30 2022-01-19 17:20:47 2 239 2022-01-19 17:20:42 1 29 2022-01-19 17:20:42 My data frequency is every 5 seconds. So, whether there’s any timestamp or not I need to get the result by assuming

How to group results according to range of datetimes on another table records

I have two tables: BusinessViews: id createdAt businessId userId 1 2022-01-19 18:00:00 1 1 2 2022-01-19 18:02:00 1 1 3 2022-01-19 18:05:00 1 1 4 2022-01-19 18:05:50 1 1 5 2022-01-19 18:07:00 1 1 6 2022-01-19 18:08:00 1 1 7 2022-01-19 18:10:00 1 1 BusinessClients: id status createdAt userId createdBy businessId 1 1 2022-01-19 18:01:00 1 1 1 2 2

extract year_month from a date column along with other columns in a sql table

I have a sql table with multiple fields including (but not limited to the following): member_id, visit_date (in datetime format eg: 2016-01-01), visit_yr_qtr (as string, eg: 2016_Q1), purchase_item (ID number), and item_price (in US dollars). I would like to extract these fields, but also include year_month (2016- January or 2016-01)as a new field in the output. This is what I

Multiple column updates in one statement – Microsoft SQL Server

I am trying to update three columns depending on three different conditions in Microsoft SQL Server. See the following example for details How would I refactor the query if I want to do it in one update statement? Appreciate your help! Answer You don’t really need the where clauses. And we can take advantage of the fact that TRY_CONVERT() will

vb.net select statement failing

I have this code to populate a DataGridView (DGV) the goal is to only populate the DGV with data from the LinkTable where one of its fields ytSiteType is equal to a global variable set on another form. The variable is gvSLT and I have tested that gvSLT makes the trip to the new form with the correct value. I

Advertisement