0

I have a table in pgadmin for postgres which holds two private keys from two other tables. Its about modeling a hospital database in PostgreSQL. I created two tables "bed" and "room". I save the private keys from this tables in a table called "bed_rooms" which will give information about how many beds are inside a room. So far the theory. I added a picture of my table "betten_zimmer" which is german and stands for "bed_rooms".

enter image description here I want to make a query which tells me how many beds a room is holding. I want to see every row with the number of beds. My next idea is to add a trigger which will fire when a room holds more than 4 beds or less than 0.

How do I make this query? AND how would the trigger look?

This is my code so far. I have 60 rooms and cant add 60 times OR .. = 5 .. 60

SELECT zimmerid, count(*)
FROM betten_zimmer
WHERE zimmerid = 1 OR zimmerid = 2 OR zimmerid = 3 OR zimmerid = 4
GROUP BY zimmerid

Thanks in advance. If anything is unclear comment this post.

0

1 Answer 1

3

If I well understood you only need a BETWEEN construct :

WHERE zimmerid BETWEEN 1 AND 60 
Sign up to request clarification or add additional context in comments.

2 Comments

SELECT zimmerid, count(*) FROM betten_zimmer WHERE zimmerid BETWEEN 1 AND 60 GROUP BY zimmerid ORDER BY zimmerid Thanks just was i looking for.
Don't ask multiple questions through comments, please open up another question ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.