简体   繁体   中英

Find and display occurrence of one value from one column which belongs to value in another column?

I have a table as shown below. Here value in column WIRE belongs to multiple MODULES . For example "134A-134A" has multiple entries in column WIRE , but MODULES for that wire have different values.

在此处输入图像描述

在此处输入图像描述

So I am trying to get a view in which I will be able to see for one WIRE which all MODULE are there.

Hope I make it clear. Thanks.

in MODULE , there are 169 unique entries and in WIRE 3k unique entries. but entire table has around 100K entries mix of diff combination of wire and module now I want to see particular wire is present in how many modules and which are those(and I want to do this for all 3k entries... so I am trying to achieve this in a single query).

I want to see the WIRE which has a distinct MODULE ,

在此处输入图像描述

I am not sure about the requirement.

Do you want the modules for which no other wire is mapped?

SELECT T.*
  FROM YOUR_TABLE T
 WHERE NOT EXISTS
       (SELECT 1 FROM YOUR_TABLE TT
         WHERE TT.MODULE = T.MODULE
           AND TT.WIRE <> T.WIRE)
   AND T.WIRE = '134A-134A';

-- Update

According to your requirement, it seems like you just want the ordering and conditional value as follows:

SELECT CASE WHEN RN = 1 THEN WIRE END AS WIRE, <ALL OTHER COLUMNS>
 FROM (SELECT ROW_NUMBER() OVER (PARTITION BY T.WIRE ORDER BY MODULE) AS RN,
              T.WIRE, <ALL OTHER COLUMNS YOU WANT>
         FROM YOUR_TABLE T) T
ORDER BY T.WIRE, T.RN

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM