I’m having a weird issue where in returning the sum of rows where a condition is true seems to only return rows if that condition is true – or at least, it is excluding a large majority of the rows that would otherwise be returned. Original query – which returns all rows: For each row that w…
Tag: join
google bigQuery subqueries to joins
I have the following table. basically simplified version of my table. I need to aggregate few columns, I will explain what I am trying to do and also what I have written till now. tableName variations can be like pizza toppings, each variation has an amount, say veggie toppings cost 10 cent and meat toppings …
How to make IN on values from cell?
I have table which contains list of data ceparated by coma eg I am trying to left joint it with IN clause, but without success Answer One option uses string functions:
GROUP BY with nested case expression – is there better way?
SQL server 2012 I am taking fees received and multiplying them by different factors based on how long the Client has been a Client. The group by clause is fairly straight forward. However, my select gets awkward when I want to use this criteria in different ways: I suppose I should mention this is a simplifie…
mySQL – Check Table for duplicates efficiently
I have a table “people” where (for simplicity) everyone has an ID, this ID is not unique so two entries can have the same ID. I now want to find all duplicates which I would do like this: SELECT p1….
SQL insert query with some condition
I am using MySQL. There are three tables presented: Patient, Occupies, Room and Privte_Patient. I need to identify the first available room and allocate the room to a newly admitted patient with PIN ‘…
Include COUNT (including 0) of grouped records
I have a table like below answers: | room | answer | |——|——–| | 001 | 3 | | 002 | 6 | | 002 | 5 | | 002 | 6 | I want to count the answers for each room. That’s …
How to fill missing dates by ID in a table in sql
I have table A which has Dates and EMPID eg below I also have Table B which has a date range My table A has missing dates and EMPID. How can I merge the two tables to have the following table. Thanks in advance. This is being used in a dataset(SQL) in SSRS. P.S. I’m new to coding in SQL
how to get sql result as objects
I have three tables: Table USER id name email Table CAMPUS id user_id (foreign key) name Table POST id title user_id (foreign key) A User belongs to a Campus, and a Post belong to a User. I want to write a query to fetch posts inner join with user inner join with campus. The result i get: [{ id username
How to calculate aggregate on inner join
I have two tables, Post & Comment. Post table contains info about posts & comment table contains the comments data about each post. Below is there structure, I need to take post_id, post_title from post table and total no of comments (using aggregate function count) on each post from comment table &am…