MySQL equation(WHERE clause)

109 Views Asked by At

I am trying to use create a graph using last months sales (plus 10% of last months production so multiplying the last months sales by 1.1). It seems it should be simple but I can't seem to figure it out, I have tried using a CASE statement

CASE
   WHEN MonthName(SaleDate) = 'Jan' THEN Count(SaleId) -- how do we limit for a particular time frame in a CASE?

I am using the MySQL version 5.7, but I am using DOMO so I can't be sure but 5.7 was the documentation they linked to

1

There are 1 best solutions below

0
AudioBubble On
SELECT
  SUM(CASE WHEN MonthName(SaleDate) = 'Jan' THEN SaleAmount END) "January Sales)
FROM my_table

NB

  • If you don't specify the year you could have the total of sales from January 2021 + January 2022.
  • I assume that the column salesId is not the value of the sale.
  • I suspect that the function month() could run faster than monthname(). WHEN MONTH(SaleDate) = 1