sql - How to count field values in mysql -
my table -
pid id subject section 1 1 7 0 2 1 12 0 3 1 13 1 4 1 13 2 5 1 13 3 6 1 14 3 7 1 14 4 8 2 15 1 9 2 16 1
result obtained -
id subject total 1 7 1 1 12 1 1 13 3 1 14 2
my query -
select distinct(subject), count(section) mytable grouping section id = 1
but throwing error, allow me know doing wrong
error
you have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'where id = 1' @ line 4: select distinct(subject), count(section) mytable grouping section id = 1
the syntax error due misplaced where
clause. needs go before group by
. additionally:
query should on line:
select subject, count(section) mytable id = 1 grouping subject
mysql sql count
No comments:
Post a Comment