Home > database >  Questions about the Mysql query!!!!!!!!!!! Urgent urgent, please answer
Questions about the Mysql query!!!!!!!!!!! Urgent urgent, please answer

Time:10-21

Ask the man answer
I was using a Mysql database
MAC, record style date
I want to check out the conditions (MAC, same date time difference for x) data of the number, could you tell me what should I do
For example, x=2

CodePudding user response:

Table associated with the cartesian product, MAC equal by x day and date

CodePudding user response:

 
If not object_id (N 'Tempdb for.. # TAB ') is null
Drop table # TAB
Go
The Create table # TAB (int [id], [je] int, (rq) Date, [xh] int)
Insert # TAB
Select 1003019100, '2019-01-07', 1 union all
Union all select 1003023100, '2019-01-05', 2
3 union all select 1007152100, '2019-01-09',
Union all select 1007152100, '2019-01-04', 4
5 union all select 1007152100, '2019-05-05',
6 union all select 1007152100, '2019-02-07',
Select 1007152100, '2019-01-06', 7
GO
- the end of the test data,
Select * from # TAB
Go
Select * from # TAB where je='100' and rq=dateadd (day, 2, '2019-01-07')


Id je rq xh
1003023 100 2019-01-05 2
  • Related