跳转到内容

Openbravo POS/开发指南/SQL 查询

来自维基教科书,一个开放世界的开放书籍

Postgres

按日期计算总销售额

SELECT date(tickets.datenew), 
SUM(productsout.price*productsout.units) AS total 
FROM tickets LEFT OUTER JOIN productsout ON tickets.ticketid=productsout.ticketid
GROUP BY date
ORDER BY date

按产品、按日期(在日期范围中)计算总计

SELECT date(datenew) AS theDate, name, SUM(units * price) AS price
FROM productsout
    LEFT OUTER JOIN products ON productsout.product=products.reference
    LEFT OUTER JOIN tickets on productsout.ticketid=tickets.ticketid

WHERE datenew BETWEEN 
'2006/2/16' AND 
'2006/2/19:23:59'

GROUP BY date(datenew),name
ORDER BY date(datenew),name

不删除产品的情况下重置数据库

?

MySQL

华夏公益教科书