sql - Applying the count function within the case function -


i relatively new sql , trying apply case function within view. while understand fundamentals of it, having difficulty applying in way need.

i have 3 columns applicationid, servername , servershared? (true/false).

each application can have many servers associated it, while each server has 1 server type.

i use case create further field can take 3 values dependent upon whether values of servershared related application true = shared, false = non-shared, both true , false = partially shared.

my thoughts using count function within case function set statements where:

  • if 'count true > 0 , count false > 0' servershared? = partially if 'count true > 0' , 'count false = 0' servershared = true , vice versa.

i believe above logic way of achieving result, yet appreciate in both how structure within case statement , wisdom if there better way.

thanks in advance!

if question right, should trick. maybe need add further columns or adapt logic. should logic behind.

select servername,      case      when count(distinct servershared) = 2          n'server shared'     when min(servershared) = 0         n'server not shared'     when max(servershared) = 1         n'server shared'     end servershared mytable  group servername 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -