mysql 쿼리 질문 드립니다. 채택완료
안녕하세요. 쿼리가 잘 안 만들어져서요.
php 함수를 만들어서 써는데요. 데이터가 많아지다 보니 페이지가 열리지 않아서요.
그래서 쿼리로 만들어야겠다 싶은데, 잘 안되네요ㅜㅜ
원하는 결과는 아래와 같습니다.
| 카테고리 | chk(Y) | chk(Y) | |
| 123 | 123 | 0 | |
| 233 | 12 | 12 |
위의 표와 같이 카테고리별 chk 에 N 값을 가지고 있는게 있고, Y 가지고 값을 가지고 있는게 있는데요.
카테고리별, 위와 같이 개수를 표기하고자 합니다.
SELECT `category`, count(*) as `cnt` FROM `new_table` where `chk` = 'N' group by `category`;
SELECT count(*) as `cnt` FROM `new_table` where `chk` = 'N' and `category` = '".$category."' and `content` = 'N';
고수님들의 고언 부탁드려요^^
답변 1개
이렇게 해결했습니다.
구글에서 어떻게 검색해야 하나 하다, mysql multiple count group by 라 검색하니 예문이 많이 나오더군요.
https://my.toonthe.com/url.php?url=https://dev.mysql.com/doc/refman/8.0/en/select.html" target="mysql_doc">SELECT category, https://my.toonthe.com/url.php?url=https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html#function_count" target="mysql_doc">COUNT(*) AS Total, https://my.toonthe.com/url.php?url=https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html#function_count" target="mysql_doc">COUNT(https://my.toonthe.com/url.php?url=https://dev.mysql.com/doc/refman/8.0/en/control-flow-functions.html#operator_case" target="mysql_doc">CASE WHEN `chk` = 'N' THEN 1 END) AS YET FROM `webtoon_modify` group by category order by YET DESC;
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인