I am having a problem with trying to count a number of rows and then grouping them in SQL.
I have used the SELECT query below to create a table.
SELECT ward.ward_no, bed_no
FROM ward, bed
WHERE ward.ward_no = bed.ward_no
.
ward_no bed_no
w1 1.
w1 2.
w1 3.
w1 4.
w2 5.
w2 6.
w2 7.
w3 8.
w3 9.
w3 10.
w4 11.
What I am trying to do is create a table where it shows each ward no ie w1 and a field showing how many fields is in it.
eg.
w1 3.
w2 3.
w3 3
I have tried the COUNT & GROUP BY fields like so…
SELECT ward.ward_no, bed_no
FROM ward, bed
WHERE ward.ward_no = bed.ward_no
AND COUNT (bed_no) AS beds_in_ward
GROUP BY ward_no;
but with no joy, any advice would be fully appreciated
You have your
COUNT()in the wrong placeI also updated the query to use
JOINinstead of the','between your tables.