Skip to content

Tag: sql

Count if the data is not unique

I have a table of store information describing which stores are linked with one another. The data might look like this: | store_id | link_num | linked_store | |   1  | 1 | 10 | |   …

Query to select records belonging only to ID and SUB-ID

I’m trying to construct a query to return only the records related to a given ID and SUB-ID. In case the condition is not met I would like to return the second possibility, i.e, the second combination ID, Sub-ID. Note: The data has thousands of IDs, but only 2 Sub-Ids per ID. This is an example of input…

SQL Combining MAX and SUM

So I have one SQL table that contains the below columns: There are ~2800 unique License numbers and will have numerous FundsIn each day. I am trying to find the last date there was activity (ActivityDate) and the sum of all of the FundsIn on that MAX ActivityDate. Below is a query I’ve been trying to mo…