List only the largest age group?

Asked

Viewed 88 times

0

inserir a descrição da imagem aquiI am trying to do an age comparison to list only the age corresponding to your age range. Ex: 20 years age range from 0 to 43.

 SELECT DISTINCT
    U.USS_CODIGO,
    t.con_codigo,
        t.CON_SEQUENCIA,
        t.PLA_NUMERO,
        t.PDT_CODIGO,
        t.PPC_DT_VIGENCIA, 
    t.PPC_IDADE_MIN, 
        t.PPC_VAL_MENSALIDADE,
    u.uss_fat_idade,

  CASE WHEN (t.PPC_IDADE_MIN >= 0 and t.PPC_IDADE_MIN <= 43)THEN ' 0 A 43 '
              WHEN (t.PPC_IDADE_MIN >= 44 and t.PPC_IDADE_MIN <= 48)THEN  '44 A 48'
              WHEN (t.PPC_IDADE_MIN >= 49 and t.PPC_IDADE_MIN <= 53)THEN  '49 A 53'
              WHEN (t.PPC_IDADE_MIN >= 54 and t.PPC_IDADE_MIN <= 58)THEN  '54 A 58'
              WHEN (t.PPC_IDADE_MIN >=59) THEN '  maior de 59 '
     END AS FAIXA_ETARIA



FROM preco_produto_contrato t, contratante c, USUARIO U
        WHERE t.PPC_DT_EXC IS NULL 

        AND c.con_dt_exc IS NULL
        AND t.pla_numero in (105)
    AND U.CON_CODIGO  = C.CON_CODIGO
        AND t.con_codigo = c.con_codigo
    AND U.Uss_Dt_Exc is null
        AND t.con_sequencia = c.con_sequencia
        ORDER BY t.con_codigo
  • What result do you get?

  • I get a list of people with their due tuition, and the ranges are the readjustment rates. however it is bringing all the bands and all the ages and not only the age and the range of it

  • I don’t understand what you want;

  • Can you display a print of the result in your question? And how would you like it to look.

  • 1

    From what you understand in the title of the question you want the largest age range of the result, would that be it? It would be more or less like this answer: http://answall.com/questions/131637/buscar-somente-o-menor-n%C3%Bamero-de-every-letter/131640#131640. Difference that you should use MAX.

  • Wouldn’t be the case to use uss_fact_age in CASE instead of PPC_IDADE_MIN ?! but for me at least it became hazy ...

  • 2021235 3131 0 105 95 01/12/2008 0 141,07 85 0 A 43 2021235 3131 0 105 95 01/12/2008 44 269,29 85 44 A 48 2021235 3131 0 105 95 01/12/2008 49 325,47 85 49 A 53&#xA;2021235 3131 0 105 95 01/12/2008 54 435,05 85 54 A 58&#xA;2021235 3131 0 105 95 01/12/2008 59 508,71 85 larger than 59 2021235 3131 0 105 96 01/12/2008 0 193,44 85 0 A 43 2021235 3131 0 105 96 01/12/2008 44 369,25 85 44 A 48&#xA;2021235 3131 0 105 96 01/12/2008 49 446,27 85 49 A 53&#xA;2021235 3131 0 105 96 01/12/2008 54 608,94 85 54 A 58&#xA;2021740 3131 0 105 95 01/12/2008 44 269,29 59 44 A 48

  • would even compare all ages and list the PPC_IDADE_MIN that corresponds to the age that this in uss_fat_age

  • SELECT ... CASE WHEN u.uss_fact_age >= 0 and u.uss_fat_age <= 43)THEN ' 0 A 43 ' WHEN (u.uss_fat_age >= 44 and u.uss_fat_age <= 48)THEN '44 A 48' WHEN (u.uss_fact_age >= 49 and u.uss_fact_age <= 53)THEN '49 A 53' WHEN (u.uss_fact_age >= 54 and u.uss_fact_age <= 58)THEN '54 A 58' WHEN (u.uss_fact_age >=59) THEN ' greater than 59 ' END AS FAIXA_ETARIA ...

  • How could I make a store Process to solve this problem

  • I didn’t understand where SP would go with the story. @Alan Darold

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.