可以使用SQL语句来比对本月和上月销售额。假设有一个名为sales的表,其中包含以下列:date,sales_amount。我们可以按以下方式查询本月和上月的销售额,并将它们显示在一起:
SELECT 
  month(date) as month, 
  year(date) as year,
  sum(case when month(date) = month(now()) then sales_amount else 0 end) as current_month_sales,
  sum(case when month(date) = month(now() - interval 1 month) then sales_amount else 0 end) as previous_month_sales
FROM 
  sales
GROUP BY 
  year, month;
通过使用月和年函数,查询会按照每个月分组并返回当前月份和上个月份的销售额总和。如果需要,可以根据需求进一步定制查询。