To show the aggregate of duplicated values that another corresponding attribute in another table is NOT NULL

JKL

Not sure if I have described the context clearly in the title but the situation is given two tables

A|B 
1|1 
1|2 
2|3 
2|4 
3|5 
4|6
5|7 
5|8 

B|C
1|NULL
2|1
3|NULL
4|NULL
5|NULL
6|2
7|3
8|4

the condition of output is the value of A should appear more than 1 time, while the corresponding B values are not both NULL in C (at least 1 value of C from B is not NULL)

what matches the conditions of the above table by A should be 1 and 5 the expected output of the count of duplicated A is 2

George Joseph

The following should help.

select t.a,count(t.a),count(t2.c)
 from t
 join t2
   on t.b=t2.b
group by t.a
having count(t.a)>1
   and count(t2.c)>=1

Here i join the table t and t2 on the column b after that i check how many records have col-a in table t are >1 and also how many in col c in t2 are> 1.

Just FYI,count(null) would be zero) so any non-null value in t2.c will have count(t2.c)>=1

Full demo

https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=6d56b0ed8bafe09786342a6bfb58b8d2

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Excel Formula - Aggregate rows by ignoring duplicated values in another column

Corresponding csv values with respect to operation(aggregate max) on another csv, pandas

How to remove duplicated/corresponding values from table?

Filling a resultant table with corresponding values (row and column) from another table

Filter values based on custom attribute in another table

Update multiple columns of a table using aggregate values from another table

On signup form INSERT -> update corresponding values in another table

Sum of attribute values by another attribute

Show an attribute from another table in a form instead the Foreign Key LARAVEL

Rename duplicated column values group by another column

Merge Values of Columns if Another Column is Duplicated

Filling a column with the amount of duplicated values in another column

Column to aggregate values in another one

Compare Values and Paste corresponding values in another sheet

SQL Server query to show old and new values from another table

SQL show a column based on another table's column values

Trigger that collect the attribute value from one table and sum it to an attribute values of another table in PostgreSQL

PyTorch - indices of corresponding values in another tensor

vba copy corresponding values from another workbook?

Replace values by indices of corresponding to another array

Return Unique values corresponding to another column in VBA

Populating a data frame with corresponding values from another

Filling in NAs with corresponding row values in another column

Simulate a hyperlink to a corresponding cell in another table

Access another table over attribute

SQL Move Attribute to another table

design table database, duplicated register or create another table?

RedShift table rows are duplicated after updating using another table

How to replace certain elements of table column with corresponding values of another array of different size in Matlab?

SQL - Select Values From A Table Where A Corresponding Value Matches The Results Of Another Select Statement