I’m trying to group my results so, instead of looking like this: id | nome | bairro ——————— 1 . |Test 1 | bairro 1 1 . |Test 1 | bairro 2 2 . |Test 2 | bairro 3 It looks like this: …
Tag: sql
What’s the best way to count the number of references based on conditions in both “home” and “away” tables?
I’m working on a project, and using Knex for it, (though if you give me raw SQL I’m pretty sure I can convert that as well.) So, here’s the sitch. I have tables ‘group’ and ‘user_group’. table ‘…
Recursively calculate product weights in product tree
I’m developing a software for Consumer price index calculation and one step of all calculation is to calculate product weights in product category. This should be done in SQL server side. I have MS …
SQL Windowing Ranks Functions
SELECT * FROM ( SELECT Product, SalesAmount, ROW_NUMBER() OVER (ORDER BY SalesAmount DESC) as RowNum, RANK() OVER (ORDER BY …
Column X which is neither GROUPED nor AGGREGATED – StandardSQL / BigQuery
I’ve been reading posts about this and the so many suggested solutions didn’t work as I want. I’m trying to get the sum of some columns for the same rows then selecting all the other columns when …
MariaDB loop not displaying results of query
I have a simple query: SELECT COUNT(ud.UserID), COUNT(DISTINCT ud.ProductID) FROM users_data AS ud JOIN products AS t ON t.ID = ud.ProductID WHERE ud.UserID = ‘3’ Which results in: COUNT(ud….
SQL-Server I’m getting crazy with workday calculation with datepart
I’m working on SQL-Server 2012 and have the following code example to get workdays between two dates DECLARE @StartDate AS date DECLARE @EndDate AS date SET @StartDate = ‘2019/02/18’ — this is a …
Filter data in one table based on data in another table
I have two tables presented below. First table contains information about indexes. Each index can be applied to one or more columns. Second table contains set of pairs: table name – column name. I …
Group By clause changes the results
I have a query like SELECT weeks_ind, weeks_rol, weeks_no, date, CASE WHEN SUM(CASE WHEN rec = ‘Y’ THEN 1 ELSE 0 END) >= 1 THEN ‘Y’ ELSE ‘N’ END “rec”, CASE WHEN (SUM( CASE WHEN glob is null …
After Search in SQL Update a column value in the found rows
I have a DB table where a Field can have several different values, I want to update a field with certain values please see table below ID Name1 Place Number 1 Key TR 3 2 Lock BG …