Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
price	   volume	mId	Dated
574.07     16106        1       2012-12-18
572.94     15044        1       2012-12-18
576.78     14197        1       2012-12-18
999.28     39669        2       2012-12-19
999.67     37937        2       2012-12-19
1006.89    37274        2       2012-12-19
870.91     56737        3       2012-12-20
865.31     49047        3       2012-12-20
865.00     43507        3       2012-12-20
 
 
Actually i need the best mID from dated 2012-12-18 to 2012-12-20. Means i need to something with price difference so that i get percentage of which category doing best.
please help me on this thanks table name is .. Marketstock
Posted 5-Feb-13 0:41am
balongi1.1K
Edited 5-Feb-13 0:44am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your requirement is not clear...hope this helps
 
select max(price) - min(price)
from table
where Dated between '18 Dec 2012' and '19 Dec 2012'
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try this
 
With Cte as
(Select mid,MAX(price)-MIN(price) as diff from test group BY mid,dated)
SELECT mid from cte where DIFF=(select MAX(diff) from cte)
 

My table and sample insert
 
 

CREATE table test
(Price decimal(18,2),
volume int,
mid int,
dated datetime)
 
INSERT INTO test values
(574.07,     16106,        1,      ' 2012-12-18'),
(572.94,     15044 ,       1,       '2012-12-18'),
(576.78 ,    14197,        1 ,      '2012-12-18'),
(999.28  ,   39669,        2,       '2012-12-19'),
(999.67  ,   37937 ,       2,       '2012-12-19'),
(1006.89 ,   37274 ,       2,       '2012-12-19'),
(870.91  ,   56737,        3  ,     '2012-12-20'),
(865.31  ,   49047,        3 ,     '2012-12-20'),
(865.00  ,   43507,        3  ,     '2012-12-20')
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100