Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Number of people from 2 selects wit UNION

Christian Pitet 2Jul 31 2025 — edited Jul 31 2025

Hi,

Under Oracle 19c, I have a table and I want to count the total number of persons adding two columns : NOMBRE_ENFANTS and NOMBRE_ADULTES.

Here are the scripts :

CREATE TABLE ve_reservation_3 (
   "ID" INT,
   "NOM" VARCHAR(17) ,
   "PRENOM" VARCHAR(12) ,
   "COURRIEL" VARCHAR(32) ,
   "TELEPHONE" VARCHAR(15) ,
   "DATE_RESERVATION" DATE,
   "NOMBRE_ADULTES" INT,
   "NOMBRE_ENFANTS" INT,
   "COMMENTAIRES" VARCHAR(306) ,
   "NOMBRE_ANIMAUX" INT,
   "HEBERGEMENT" VARCHAR(8) ,
   "DATE_FIN_RESERVATION" DATE,
   "ADRESSE" VARCHAR(33) ,
   "ELECTRICITE" INT,
   "TOTAL" INT,
   "VEHICULE" INT,
   "NOMBRE_VEHICULES" INT,
   "PAYS" VARCHAR(51) ,
   "DON" INT,
   "PRIX" INT,
   "DATE_REGLEMENT" DATE,
   "MOYEN_REGLEMENT" VARCHAR(21) ,
   "REGLE" VARCHAR(9) ,
   "CREEE_LE" DATE,
   "CODE_POSTAL" VARCHAR(11) ,
   "VILLE" VARCHAR(16) 
);
***Moderator action: removed insert statements as they contain personal information (again). Please don't post names, phine number and mail addresses or any other vbalid personal data here!
Next Time the postwill be removed! ***

I have written a sql command but I don't know how to calculate the total number of persons :

select vr.hebergement,
      vr.date_reservation, vr.date_fin_reservation       
 from ve_reservation_3 vr
 where hebergement = 'Tente'
 group by vr.hebergement,  vr.date_reservation, vr.date_fin_reservation
 UNION
 select vr.hebergement,
      vr.date_reservation, vr.date_fin_reservation       
 from ve_reservation_3 vr
 where hebergement <> 'Tente'
 group by vr.hebergement,  vr.date_reservation, vr.date_fin_reservation

How to calculate the number of persons ? I want to have a result if this number is less than 20.

Best regards.

This post has been answered by Cookiemonster76 on Jul 31 2025
Jump to Answer
Comments
Post Details
Added on Jul 31 2025
18 comments
242 views