MySQL创建视图

查询每天的订单金额
-- CREATE VIEW  order_day_amount as  
SELECT
	FROM_UNIXTIME(ctime, '%Y-%m-%d') AS order_day,
	sum(order_amount) / 100 as 合计
FROM
	`shop_order` 
GROUP BY order_day HAVING order_day > FROM_UNIXTIME(  (UNIX_TIMESTAMP() - 86400 ), '%Y-%m-%d' )




-- SELECT * from order_day_amount 

查询最近七天每天的订单金额

SELECT

	FROM_UNIXTIME(ctime, '%Y-%m-%d') AS order_day,
	
sum(order_amount) / 100 AS 合计

FROM
	`shop_order`

GROUP BY
	order_day

HAVING

	
order_day > FROM_UNIXTIME(
		(UNIX_TIMESTAMP() - 86400 *7 ),

		'%Y-%m-%d'
	) 

展开阅读全文

没有更多推荐了,返回首页