Home > database >  Find out the value of the date of the first two in the same table for more than 1 times the value of
Find out the value of the date of the first two in the same table for more than 1 times the value of

Time:10-31

Data and the structure is as follows:


Find out the different code of two recent date (date in descending order) CHG division by a value greater than 1,

Such as: 000001 17 CHG 2.36 divided by 16 0.06 is greater than 1 meet the condition.
and 000004 does not meet the conditions
Hope great god can use an SQL expression, thank you very much!!!!!!!!!!!

CodePudding user response:

Select * from table a
Join table b on a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1

CodePudding user response:

reference 1st floor csdn_castiel response:
select * from table a
Join table b on a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1


Can't perform, there is only one table stock

CodePudding user response:

refer to the second floor reyoreyoreyo response:
Quote: refer to 1st floor csdn_castiel response:

Select * from table a
Join table b on a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1


Can't perform, there is only one table stock

Yes
Select * from stock a
The join stock b on a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1

CodePudding user response:

refer to the second floor reyoreyoreyo response:
Quote: refer to 1st floor csdn_castiel response:

Select * from table a
Join table b on a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1


Can't perform, there is only one table stock
, there is in the reverse order row of time, before taking only two

CodePudding user response:

reference 4 floor reyoreyoreyo response:
Quote: refer to the second floor reyoreyoreyo response:

Quote: refer to 1st floor csdn_castiel response:

Select * from table a
Join table b on a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1


Can't perform, there is only one table stock
, there is in the reverse order row of time, only take two before


Select * from stock a
The where (select count (*) from stock where code=a.c ode and dateThe order by a.c ode asc, a. d. ate desc

CodePudding user response:

reference 5 floor csdn_castiel reply:
Quote: refer to 4th floor reyoreyoreyo response:

Quote: refer to the second floor reyoreyoreyo response:

Quote: refer to 1st floor csdn_castiel response:

Select * from table a
Join table b on a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1


Can't perform, there is only one table stock
, there is in the reverse order row of time, only take two before


Select * from stock a
The where (select count (*) from stock where code=a.c ode and dateThe order by a.c ode asc, a. d. ate desc


Don't know if I didn't express clearly,

Find out the different code of two recent date (date in descending order) CHG division by a value greater than 1 data (date of the latest one),

Such as: 000001 17 CHG 2.36 divided by 16 0.06 is greater than 1 meet the condition.
and 000004 does not meet the conditions
Hope great god can use an SQL expression, thank you very much!!!!!!!!!!!

CodePudding user response:

Select * from stock a
The where (select count (*) from stock where code=a.c ode and date> A. d. ate) & lt; 2
The result is equivalent to a list
To paraphrase another began writing SQL

Select * from
(select * from stock a
The where (select count (*) from stock where code=a.c ode and date> A. d. ate) & lt; 2) a

The join
(select * from stock a
The where (select count (*) from stock where code=a.c ode and date> A. d. ate) & lt; 2) b

On a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1

Is the SQL efficiency is very low

CodePudding user response:

refer to 7th floor csdn_castiel response:
select * from stock a
The where (select count (*) from stock where code=a.c ode and date> A. d. ate) & lt; 2
The result is equivalent to a list
To paraphrase another began writing SQL

Select * from
(select * from stock a
The where (select count (*) from stock where code=a.c ode and date> A. d. ate) & lt; 2) a

The join
(select * from stock a
The where (select count (*) from stock where code=a.c ode and date> A. d. ate) & lt; 2) b

On a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where biggest hg/a.c hg> 1

Is the low efficiency of SQL


This not line, the along while have no reaction, 4000 data,,
Select * from stock_market a
The join stock_market b on a.c ode=biggest ode and Anderson, d! B.i=d and b.d ate> A. d. ate
Where b.o bv/a.o bv> 5
This article also can be optimized to improve it?

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related