Home > database >  Rookie help sincerely: simple SQL statements
Rookie help sincerely: simple SQL statements

Time:09-23

Existing table 1: contains the fields ID, department, sales, date, a total of four fields, I want to achieve:" department, less than or equal to the date of July 4, 2006, sales of summary, the date is greater than the sales summary "in July 2006 requirements are shown on a table, kneel beg: how do you write SQL statement? Really, really is a beginner rookie of 2 days, we guide, genuflect is begged

CodePudding user response:

Select department, the sum (sales) as xl
The from TB
Where the date & lt; '2006/7/5'
Group by department

CodePudding user response:

According to the department of statistics is? Or all the summary?

CodePudding user response:

According to the department summary:
 select sum (case when date & lt; Then sales else 0='2006-7-4' end) as sales] [in the 2006-7-4 s and before, the sum (the case when the date & gt; '2006-7-4' then sales else 0 end) as [the 2006-7-4 after sales] 
From table 1 group by department

  • Related