简体   繁体   English

分组并显示所有行

[英]Group by and show all rows

I have a table called payment. 我有一张叫付款表。 Which has payid , date , productid , customerid , Name , type , colour , quantity , total . 其中有payiddateproductidcustomeridNametypecolourquantitytotal

Multiple items can be entered into the table with the same timestamp. 可以将具有相同时间戳的多个项目输入到表中。

I am trying to group the data by date. 我正在尝试按日期对数据进行分组。 I have got the date to display only once using count but it will only display the first item with the time stamp. 我使用date只能显示一次日期,但它只会显示带有时间戳的第一项。

<?php
include("db_connect.php");

//echo "1"; 
$get_orders_date = mysql_query("SELECT date, name, COUNT( DISTINCT date) FROM payment GROUP BY date");

//echo "2"; 

while($get_date = mysql_fetch_array($get_orders_date)) 
{   
    //echo "3"; 

    $date = $get_date['date'];  
    echo "" .$date. "<br/><br/>";
    $name = $get_date['name'];  
    echo "" .$name. "<br/><br/>";
}

?>

This will display the date and time the item was paid for but only one of the items. 这将显示付款日期和时间,但仅显示其中一项。

Thanks for the help :) 谢谢您的帮助 :)

Group by both name and date. 按名称和日期分组。

Also keep in mind that MySQL violates standards by executing this query. 还请记住,MySQL通过执行此查询违反了标准。 If using grouping, all nongrouped columns should have an aggregate function applied to them. 如果使用分组,则所有未分组的列都应应用聚合函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM