Summing totals from nested and unnested data in a single query

Tags: ,


I am working on nested Google Analytics data to build a query, I need to unnest 3 levels in order to get all the fields I need, but once I have unnested the SUM() of my .totals fields are far too high,...

Tags: postgresql sql

Input of anonymous composite types is not implemented – Postgres

Tags: ,


I have a table with an XML column. The XML can contain an optional link element. 1d177dee-1da4-4451-b175-396666afc370 I ...

SQL: Running Total of Occurrences

Tags: , ,


I am using Metabase with a PostgreSQL implementation. I'd like to achieve the outcome in the photo. I wish to include a column that counts how many times a field has occurred above. It should include ...

Query HAVING MAX() doesn’t work as expected

Tags: , ,


I have four tables in a database. the tables are like the following: Cashier(cashier_id*, cashier_name) Category(category_id*, category_name) Product(product_id*, product_name, price, category_id**) ...

Excel VBA – Stored Procedure (SQL Server)

Tags: , , , ,


I have a slight issue retrieving multiple recordsets (with column names) and pasting the data into an Excel sheet, like the image below The VBA code that I have just retrieves the first recordset but ...

Tags: .net c# sql sqlkata

How to join multiple WHERE clauses together in SqlKata?

Tags: , , ,


I am using SqlKata to creating dynamic SQL queries. I have a list of conditions, stored in my database, which are generated according to my business rules. this is my code sample: var list = new List&...

Teradata Dynamic SQL with Bind Variables?

Tags: , ,


Is it possible to use bind variables in a Teradata dynamic SQL statement? I can't find an example anywhere. I'm looking to do something like this: DECLARE SQLString VARCHAR(1000) SET SQLString = '...

Query to find the city name with longest and shortest length

Tags: , , ,


I've written a query to return me the cities with the shortest and longest length strings in a MS SQL SERVER database. Select city, len(city) as l From Station Where len(city) in ((select max(len(...

How to join two tables with the same number of rows in SQLite?

Tags: , , ,


I have almost the same problem as described in this question. I have two tables with the same number of rows, and I would like to join them together one by one. The tables are ordered, and I would ...

SQL code patterns mapped to Matlab operations on `table’s`

Tags: , ,


I'm quite comfortable (and somewhat critically dependent) on Microsoft Access (SQL 92) code idioms patterns, including nested SELECTs, various JOINs, filtering, column ordering, and aliasing of ...