[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 529
  • Last Modified:

SELECT Count with CASE

Hi guys, I am trying to do a SQL statement fo this matter:

I need to return 1 (for true) if in my table user_tables I got for my column isJoin  the count of 6 .
in addition to the count, I need check there is no value of 0 on that column.   Example:

IsJoin:  1 2 3 0 0 4
Count = 6 , but got 2 zero, So i would return false.

Example:

IsJoin :  1 2 3 4 5 6
count = 6, no zero:   Return true.


I didnt find the way to do it in SQl.. can you help ?
0
PhilippeRenaud
Asked:
PhilippeRenaud
1 Solution
 
TimCotteeCommented:
Hi PhilippeRenaud,

Select Case When (Select Sum(Case When IsJoin = 0 Then 0 Else 1 End) As [Count] From User_Tables) = 6 Then 1 Else 0 End As Result

For example.

Tim Cottee
0
 
Aneesh RetnakaranDatabase AdministratorCommented:

SELECT CASE WHEN(Select Count(isJoin) FROM user_tables where isJoin >0 ) = 6 then 1 ELSE o END as Status
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now