. 당신이 역 따옴표로 묶어야 할 수 있도록 read
는, MySQL은 예약어입니다
는
SELECT CONCAT('You have ',
COUNT(`read`),
' unread msg to your number ',
customer,
' customer') AS news
FROM msg
WHERE `read` = '0' AND `sent_to` = '45'
GROUP BY customer;
참고. (Source)
테스트 케이스 :
CREATE TABLE msg (
`sent_to` int,
`customer` int,
`msg` varchar(10),
`read` int
);
INSERT INTO msg VALUES(45, 3, 'bla', 0);
INSERT INTO msg VALUES(34, 4, 'bla', 1);
INSERT INTO msg VALUES(34, 6, 'bla', 0);
INSERT INTO msg VALUES(45, 3, 'bla', 0);
INSERT INTO msg VALUES(56, 7, 'bla', 1);
INSERT INTO msg VALUES(45, 8, 'bla', 0);
질의 결과 :
+-------------------------------------------------+
| news |
+-------------------------------------------------+
| You have 2 unread msg to your number 3 customer |
| You have 1 unread msg to your number 8 customer |
+-------------------------------------------------+
2 rows in set (0.00 sec)
위대한 답변을 주셔서 감사합니다 및 또한 "읽기"에 대한 정보를 제공, 나는 문제가있다, mysql_num_rows는 0 비록 내가 "읽기 = 0"데이터베이스에 있습니까? –
오 그래, 내가 그걸 고쳤어. –