i am trying to count sub_tag_1,sub_tag_2,sub_tag_3 columns only when where condition is true and in the last i want sum of all three columns as a result.
here is my virtual table :
+---+-----------+-----------+-----------+
| id| sub_tag_1 | sub_tag_2 | sub_tag_3 |
+---+-----------+-----------+-----------+
| 1 | php | | |
| 2 | mysql | php | |
| 3 | java | | php |
+---+-----------+---------+-------------+
i already try so many times but i failed every time and here my sql query:
1) SELECT count(`sub_tag_1`) AND count(`sub_tag_2`) AND count(`sub_tag_3`)
FROM posts where `sub_tag_1`
LIKE "php" and `sub_tag_2` LIKE "php" and `sub_tag_3` LIKE "php";
above query executed successfully but it didn't match any thing in database and it return 0
2) SELECT count(`sub_tag_1`) AND count(`sub_tag_2`) AND count(`sub_tag_3`)
FROM posts where `sub_tag_1` = "php" and `sub_tag_2` = "php"
and `sub_tag_3` = "php"
and sum(count(`sub_tag_1`)+count(`sub_tag_2`)+count(`sub_tag_3`));
above query give me error: Invalid use of group function
Please advice and explain step by step how can i do this..