我有一个“交易”表,列有:transactionDateTime,quantity,clientName,sellerName,transactionType (出售/购买).
现在,我在网页(php)的表中列出了所有这些事务。我想在列表中添加,每个交易类型(买卖)每个‘卖方’的每日摘要,。因此,至少我要查找的是使用表执行摘要的查询,最大限度(不确定是否可能)是一个查询,在transactionDateTime转到新的一天后,该查询会执行与以前相同的平面列表,再加上摘要结果。
提前谢谢你。
交易表样本:
transactionDateTime,数量,价格,clientName,stationID,transactionType,卖方,typeID
现在,我正在网页上列出几乎未处理的行数据。我想要的应该是每天一样的列表+摘要。比如:
在SQL查询中是否可能出现这种情况?或者我应该通过编程方法来做到这一点?
发布于 2014-02-02 17:13:46
像这样的事情应该能起作用:
/* Your details. */
select 'DETAIL' type_of_record
,      1 sorting_order
,      something_to_order_details_on sorting_order_detail
,      transactionType
,      sellerName
,      transactionDateTime
,      quantity
,      price
from   transactions
union
all
/* Your totals. */
select 'DAILY' type_of_record
,      2 sorting_order
,      null sorting_order_detail
,      transactionType
,      sellerName
,      trunc(transactionDateTime) /* Or whatever MySQL uses to round dates. */
,      sum(quantity) quantity_sum
,      sum(price) price_sum
from   transactions
where  transactionDateTime < trunc(now)
order
by     sorting_order
,      sorting_order_detailhttps://stackoverflow.com/questions/21512208
复制相似问题