在我的sql中,我有一个如下表。在那个表中我有topicID,它不是主键,只是为了说清楚。我正在努力编写一个可以在表中给出相同topicID计数的脚本。
if ($result['success'] == 1) {
$webmaster_email = "tutorial@androidstackoverflow.com";
$feedback_page = "contact-mail.php";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$message = strip_tags($message);
$message = preg_replace("/[^a-zA-Z0-9\s]/", "", $message);
$name = $_REQUEST['name'] ;
$msg =
"Name: " . $name . "\r\n" .
"Email: " . $email . "\r\n" .
"Message: " . $message = wordwrap($message, 70, "\n", true);
例如:
topicID | description | date |
| 1 | xyz | 2018-11-11 |
| 1 | xyz | 2018-11-11 |
| 2 | xyz | 2018-11-11 |
| 1 | xyz | 2018-11-11 |
| 3 | xyz | 2018-11-11 |
| 3 | xyz | 2018-11-11 |
| 2 | xyz | 2018-11-11 |
| 1 | xyz | 2018-11-11 |
答案 0 :(得分:2)
你需要的是Group BY表达。请尝试以下方法,
select topicId as 'Topic Id' ,count(*) as 'Number of times' from my_table group by topicId