Home > database >  How to write the date on condition that the <=SQL of data for a period of time
How to write the date on condition that the <=SQL of data for a period of time

Time:09-27

Headings are harder to read the text
To a list of some data with the name and the date attribute
before the purpose is to take one day, all the name
SQL statements are:
 select the name from the table where the date & lt; Group by name='20170911' 

The question now is I want to take a month or even longer data I don't know how to write SQL statements, which is by the end of the no. 1 in the table how many name, by 2 and how many a name,
Which is the result to
name date
a 20170901
B 20170901
A 20170902
B 20170902
C 20170902

If not a SQL written word can use stored procedures or something, I'm not very familiar with SQL, troublesome everybody eldest brother help me take a look at how to write I use DB2,

CodePudding user response:

The meaning of the original poster is to statistics the month by the until yesterday? Conditions:

The date between trunc (sysdate, 'mm) and trunc (sysdate - 1)

CodePudding user response:

Is such a mean
For example,
A table record is each student admission information
Xiao Ming is school on September 1
Xiao wang is on September 2 entrance
Xiao zhang is on September 3 school
So to statistics by September 2 and how many students are
 select the name from the table where date<='20170902' group by name - (assuming the name is not repeated) 

Then I want to get the following statements one-time
Xiao Ming 20170901
Xiao Ming 20170902
Wang 20170902
Xiao Ming 20170903
Wang 20170903
Xiao zhang, 20170903

CodePudding user response:

refer to the second floor DaRiFuTu response:
is such a mean
For example,
A table record is each student admission information
Xiao Ming is school on September 1
Xiao wang is on September 2 entrance
Xiao zhang is on September 3 school
So to statistics by September 2 and how many students are
 select the name from the table where date<='20170902' group by name - (assuming the name is not repeated) 

Then I want to get the following statements one-time
Xiao Ming 20170901
Xiao Ming 20170902
Wang 20170902
Xiao Ming 20170903
Wang 20170903
Zhang 20170903


Don't understand, want to know every students name?

refer to the second floor DaRiFuTu response:
is such a mean
For example,
A table record is each student admission information
Xiao Ming is school on September 1
Xiao wang is on September 2 entrance
Xiao zhang is on September 3 school
So to statistics by September 2 and how many students are
 select the name from the table where date<='20170902' group by name - (assuming the name is not repeated) 

Then I want to get the following statements one-time
Xiao Ming 20170901
Xiao Ming 20170902
Wang 20170902
Xiao Ming 20170903
Wang 20170903
Zhang 20170903


Group by the name, the date?
  • Related