Oracle plsql how to choose if two accounts are equal

I want to select data from the table if and only if the unique mobile numbers are equal to the total number of rows in the table (i.e. we do not have two different people with the same mobile number and / or we do not have a row with zero values ​​in the column mobile number), where there is a specific area code, for example 4817.

At the moment, I have a request below (which does not work with AND restriction). Does anyone have any tips on how to do this?

SELECT  
  MOB_NUM   AS MOBILE_NUMBER,
  NAME      AS NAME,
  AREA_CODE AS AREA_CODE

  FROM DB_PHONEBOOK DBP
  WHERE DBP.AREA_CODE = 4817
  AND (COUNT(DISTINCT DBP.MOB_NUM ) = COUNT(DBP.MOB_NUM))
+4
source share
1 answer

Individual rows / records are filtered using a sentence Where, where as groups, such as count / Sum / Average / .., are filtered using a sentenceHaving

, -

SELECT DBP.MOB_NUM   AS MOBILE_NUMBER,
       DBP.NAME      AS NAME,
       DBP.AREA_CODE AS AREA_CODE
FROM   DB_PHONEBOOK DBP
       INNER JOIN (SELECT MOB_NUM
                   FROM   DB_PHONEBOOK DBP
                   WHERE  DBP.AREA_CODE = 4817
                   GROUP  BY MOB_NUM
                   HAVING Count(DISTINCT DBP.MOB_NUM) = Count(DBP.MOB_NUM)) C_DBP
               ON DBP.MOB_NUM = C_DBP.MOB_NUM
WHERE  DBP.AREA_CODE = 4817 
+2

Source: https://habr.com/ru/post/1680933/


All Articles