January 24, 2018 at 2:30 pm
Hi guys,
My code :
Select A.price1, B.price2 from
(SELECT Top 100 tarih, coin, MIN(price) AS price1
FROM dbo.cointahmin
GROUP BY tarih, coin order by tarih desc,coin) A,
(SELECT Top 100 tarih, coin, MIN(price) AS price2
FROM dbo.cointahmin
GROUP BY tarih, coin order by tarih desc,coin) B
Normally the queries are the same, the results should be the same,
All the values of A are the same. In B, there are different values (B)
What is the reason for this and what should be the question?
January 24, 2018 at 2:38 pm
This is not a problem at all. It's doing exactly what you are telling it to do.
You have create a full join. Every row in A will be joined to every row in B.
In the example you gave, the first row of A contains the value of 0.00005644. That row is being joined to every single row in B.
Scroll down, you will see A display 0.00017480, again joined to every row in B
What exactly are you trying to accomplish?
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
January 24, 2018 at 2:39 pm
Not sure what your problem is here. I see a CROSS JOIN (Cartesian Product) between two derived tables, but nothing saying what may be wrong.
January 24, 2018 at 2:42 pm
What should I do if two or more rows contain the same values?
Normally my guess is that the code I wrote does not have to be the same?
January 24, 2018 at 2:47 pm
xtrmus2319 - Wednesday, January 24, 2018 2:42 PMWhat should I do if two or more rows contain the same values?Normally my guess is that the code I wrote does not have to be the same?
Can't answer this question without know what it is you are trying to accomplish.
January 24, 2018 at 2:47 pm
Are you expect row 1 to have the same value in both columns, row 2 to have the same value for both columns, row 3 to have...? That's not what the SQL you've provided there is doing, that's why.
In very simplistic terms, you've effectively written a query like this:
Notice that you get 100 rows from this query, as every row is joined with every row.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
January 24, 2018 at 2:55 pm
Normally i want to Divide a.price/b.price with this code. Because I want to see the next change in 3 minutes.
Select a.tarih,a.coin,(A.price),b.tarih,b.coin,(B.price) from (SELECT tarih, coin, MIN(price ) AS price
FROM dbo.cointahmin
GROUP BY tarih, coin order by tarih desc,coin OFFSET 300 ROWS
FETCH NEXT 100 ROWS ONLY) A,
(SELECT Top 100 tarih, coin, MIN(price ) AS price
FROM dbo.cointahmin
GROUP BY tarih, coin order by tarih desc,coin) B
January 24, 2018 at 3:09 pm
xtrmus2319 - Wednesday, January 24, 2018 2:55 PMNormally i want to Divide a.price/b.price with this code. Because I want to see the next change in 3 minutes.
What is your question here though? You haven't yet explained the result set you were expecting either. Could you try to elaborate please?
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
January 24, 2018 at 3:15 pm
My question;
Create a new column. In this column I would like to show the ratio of A.Price / B.Price when 3 minutes before(a.price) and current data(B.price) with same coin.
ADA/BTC A.price/B.price
ADX/BTC A.price/B.price
...
...
...
ZRT/BTC A.price/B.price
Thanks.Is it understandable?
January 24, 2018 at 3:45 pm
xtrmus2319 - Wednesday, January 24, 2018 3:15 PMMy question;
Create a new column. In this column I would like to show the ratio of A.Price / B.Price when 3 minutes before(a.price) and current data(B.price) with same coin.ADA/BTC A.price/B.price
ADX/BTC A.price/B.price
...
...
...
ZRT/BTC A.price/B.priceThanks.Is it understandable?
Yes but what you're trying really just isn't the way SQL works.
A) As has been said you've created a cartesian join which means that every row in each result set will be joined together., that's why your result set has 10000 rows and many values where the coins don't match.
B) To generate the result sets you expect/describe would require some very specific assumptions and will be either missing data or just wrong if those assumptions aren't true
C) You're assuming data will come in exact chunks of 100 and have exactly 1 batch per minute to generate you're expected resulting offset of 100 rows current vs. 3 minutes ago and the coins in each batch will always be the same
D) Even if the above is true the query could only be run while no data is being added
What is the purpose of this query? Do you need to compare the value of a coin vs the same coin from exactly three minutes ago? Do you get coins that don't meet any of the assumptions above?
January 24, 2018 at 11:14 pm
I need to compare the value of a coin vs the same coin from exactly three minutes ago. Yes 🙂
All data must meet all the values.
Is there a way to do this?
January 25, 2018 at 2:22 am
xtrmus2319 - Wednesday, January 24, 2018 11:14 PMI need to compare the value of a coin vs the same coin from exactly three minutes ago. Yes 🙂
All data must meet all the values.Is there a way to do this?
Can you supply some sample data and DDL please? Have a look in my signature on how to psot this.
I'm thinking this might more easily be possible using LEAD/LAG.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
January 25, 2018 at 2:38 am
Thom A - Thursday, January 25, 2018 2:22 AMxtrmus2319 - Wednesday, January 24, 2018 11:14 PMI need to compare the value of a coin vs the same coin from exactly three minutes ago. Yes 🙂
All data must meet all the values.Is there a way to do this?
Can you supply some sample data and DDL please? Have a look in my signature on how to psot this.
I'm thinking this might more easily be possible using LEAD/LAG.
I get 100 different coins every minute
I want to divide the current data with the data 3 minutes ago the same coin
Create a new column. In this column I would like to show the ratio of A.Price / B.Price when 3 minutes before(a.price) and current data(B.price) with same coin.
Example
Coin New Column
ADA/BTC A.price/B.price
ADX/BTC A.price/B.price
...
...
...
ZRT/BTC A.price/B.price
January 25, 2018 at 2:52 am
xtrmus2319 - Thursday, January 25, 2018 2:38 AMI get 100 different coins every minuteI want to divide the current data with the data 3 minutes ago the same coin
Create a new column. In this column I would like to show the ratio of A.Price / B.Price when 3 minutes before(a.price) and current data(B.price) with same coin.Example
Coin New Column
ADA/BTC A.price/B.price
ADX/BTC A.price/B.price
...
...
...
ZRT/BTC A.price/B.price
Have a look at the link in my signature. We need consumable data and DDL.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
January 25, 2018 at 3:04 am
Thom A - Thursday, January 25, 2018 2:52 AMxtrmus2319 - Thursday, January 25, 2018 2:38 AMI get 100 different coins every minuteI want to divide the current data with the data 3 minutes ago the same coin
Create a new column. In this column I would like to show the ratio of A.Price / B.Price when 3 minutes before(a.price) and current data(B.price) with same coin.Example
Coin New Column
ADA/BTC A.price/B.price
ADX/BTC A.price/B.price
...
...
...
ZRT/BTC A.price/B.priceHave a look at the link in my signature. We need consumable data and DDL.
consumable data and DDL ?
You need just code ? Right?
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply