0
Good evening! I’m new to the programming.
I have the code below in a CTE that counts the number of subscribers in each area.
In the main consultation I see which area has the largest amount of subscriber.
I would like to return the numerical value as it is already appearing, but concatenate with the name of the area of major interest. But I’m not getting it because one value is integer and the other string. Or at least put the name of the area with more amount in another column. Could you help me? Thank you
WITH CTE AS(
SELECT TOP 1 INSCRITO.IDPS AS ID,
(SELECT
COUNT (*) AS A FROM INSCRITO
WHERE IDAREAINTERESSE = 51 ) AS A,
(SELECT COUNT (*) AS A FROM INSCRITO
WHERE IDAREAINTERESSE = 52 ) AS B,
(SELECT
COUNT (*) FROM INSCRITO
WHERE IDAREAINTERESSE = 53) AS C
FROM INSCRITO) SELECT ID,
(CASE
WHEN A > B AND A > C THEN A
WHEN B > A AND B > C THEN B
WHEN C > A AND C > B THEN C
END) AS MAIOR,
(CASE
WHEN A < B AND A < C THEN A
WHEN B < A AND B < C THEN B
WHEN C < A AND C < B THEN C
END) AS MENOR
FROM CTE
"because one value is integer and the other string", then just convert the whole value to string
– Ricardo Pontual
If you are using Postgresql use the function
to_char
to format its numeric value to string the desired way.– anonimo
What is the database manager?
– José Diz