我正在尝试在spiceworks中创建一个需要上个月数据的报告。我在这里看到了这个链接:Query last day, last week, last month SQLite但是月份示例仅返回当前月份。我需要上个月。报告将在每个月的第一天运行,这是我迄今为止所做的:
SELECT a.id as "Ticket #", c.first_name||' '|| c.last_name as "Created By", a.c_location as "Location",
a.c_hud as "HUD", a.closed_at as "Closed", a.c_urgency as "Urgency", a.category as "Category",
a.summary as "Summary", SUM(b.time_spent)/3600.0 as "Time Spent (Hrs)",
d.price*d.quantity as "Purchases"
FROM tickets a
LEFT OUTER JOIN ticket_work b ON a.id = b.ticket_id
LEFT OUTER JOIN purchase_list_items d on a.id = d.ticket_id
JOIN users c ON a.created_by = c.id
WHERE closed_at BETWEEN datetime('now', 'start of month') AND datetime('now','localtime')
GROUP BY a.id
ORDER BY c_location;
一旦我得到了正确的数据集,我就必须将整数b.time_spent字段转换为小时格式。因此,如果花费的时间总和为33600,我需要将输出转换为9.33,这是它当前给出的9。它目前只给予我任何帮助将不胜感激。
答案 0 :(得分:2)
要进行浮点除法,至少有一个数字必须是浮点数。 使用:
SUM(b.time_spent) / 3600.0