| Author |
Topic |
|
SamC
White Water Yakist
3467 Posts |
Posted - 2002-12-05 : 09:52:46
|
| I'm capturing display resolution of course users and have found that the Javascript returns values that sometimes are the width less the scrollbar, titlebar and so on. I want to count the users that fall into the following catagories640x480800x6001024x7681280x10241400x10501600x1200higherMaybe I should Update the data and using a CASE statement, store it in one of the 4 formats above.Could the data be left raw, and a simple query constructed to provide the counts above?SamSample data follows..select ResWidth, ResHeight, count(*) as totalfrom ClientStatsgroup by ResWidth, Resheightorder by reswidth, resheight----------------------------------ResWidth,ResHeight, Count(*)-1,-1,10640,452,2759,556,1759,565,1759,572,1767,497,1767,547,1767,560,1767,567,1767,569,1767,571,1767,572,37767,600,1768,572,1768,990,1776,533,1798,572,5798,600,2800,490,1800,508,1800,540,6800,547,1800,566,2800,567,1800,568,7800,569,2800,570,3800,571,2800,572,200800,594,1800,598,1800,600,28856,452,1963,768,2983,732,1983,738,1983,740,3991,676,1991,705,1991,715,3991,728,1991,732,1991,734,1991,736,1991,738,5991,740,451022,739,11022,740,51022,768,11024,676,11024,690,11024,695,11024,696,21024,703,11024,705,11024,707,11024,708,131024,715,101024,726,11024,728,11024,733,111024,734,141024,735,61024,736,41024,737,11024,738,91024,739,61024,740,1461024,768,141024,1250,11119,835,11119,836,21152,770,11152,772,11152,830,11152,836,71152,864,11239,991,11247,996,41247,1024,11280,907,11280,932,11280,943,11280,961,11280,964,31280,989,11280,990,11280,991,21280,992,11280,994,21280,995,11280,996,111600,600,11600,1115,12046,740,12048,729,12048,734,12048,740,1 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-12-05 : 11:45:36
|
| If you cross joined the categories with the clients where A.reswidth <= B.reswidth and A.ResHeight <= B.ResHeight and calculate the difference at the same time. Next take the MIN() difference that would filter out the 640x480 - 1022,739 combinations for example.Next you could group by the categories column. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2002-12-05 : 12:04:07
|
| I would create two tables of your possible resolutions for the Row and the Columns first:RowValues-------4806007681024..etc..ColValues--------64080010241280..etc...This way you don't have to worry about all combinations. Next, decide on your ranges for each of; that is, it must be with 50 pixels to be considered in that category.Also, I am assuming the ClientStats table has a primary key of something like "ID".Then you have:SELECT C.ID, A.Rows as RowResolution, A.Cols as ColResolutionFROMClientStats CINNER JOIN(SELECT Rows, Cols FROM RowValues CROSS JOIN ColumnValues) AON ABS(C.ResWidth - A.Cols) < 50 AND ABS(C.ResHeight - A.Rows) < 50You can get a count per resolution by using:SELECT RowResolution, ColResolution, COUNT(*) as NumberFROM(...above SQL..) AGROUP BY RowResolution, ColResolution- Jeff |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-12-05 : 12:15:48
|
| The problem with using the CROSS JOIN that way is you can end up with a 640x1200 screen resolution, which isn't a valid combination...although a window could be sized that way, the screen is running at 1600x1200.If you add another table:CREATE TABLE Screens (Rows int NOT NULL REFERENCES RowValues (Rows),Cols int NOT NULL REFERENCES ColValues (cols)CONSTRAINT PK_Rows_Cols PRIMARY KEY (Rows, Cols) )You can then populate it with valid screen resolution combos and use it in the same query instead of the CROSS JOIN version. |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2002-12-05 : 12:42:44
|
| i figured the cross join is just quicker and easier to write. the INNER JOIN should remove all invalid combinations. It depends what results you are looking for. Plus, if the resolution is some weird combo because of the way the user sized the window, at least it would still be returned so you could decide how to categorize that later. - JeffEdited by - jsmith8858 on 12/05/2002 12:44:57 |
 |
|
|
SamC
White Water Yakist
3467 Posts |
Posted - 2002-12-05 : 12:43:57
|
| Thank you everyone. I combined your ideas like this:DROP TABLE ResWidthsgoCREATE TABLE ResWidths (ResWidth INT NOT NULL)GOINSERT INTO ResWidths (ResWidth) VALUES(-2)INSERT INTO ResWidths (ResWidth) VALUES(100)INSERT INTO ResWidths (ResWidth) VALUES(640)INSERT INTO ResWidths (ResWidth) VALUES(800)INSERT INTO ResWidths (ResWidth) VALUES(1024)INSERT INTO ResWidths (ResWidth) VALUES(1280)INSERT INTO ResWidths (ResWidth) VALUES(1400)INSERT INTO ResWidths (ResWidth) VALUES(1600)INSERT INTO ResWidths (ResWidth) VALUES(2048)GOSELECT X.Upper, Count(*) AS Total, CAST(Count(*) * 100.0 / (SELECT COUNT(*) FROM ClientStats) AS NUMERIC(5,1)) as Percentage FROM(select A.ResWidth as Upper, Max(B.ResWidth) as Lower from ResWidths A cross join Reswidths BWHERE A.Reswidth > B.ResWidthGROUP BY A.ResWidth) XINNER JOIN ClientStats CS ON CS.Reswidth <= X.Upper AND CS.ResWidth > X.LowerGroup by X.UpperRESULTS-------Upper,Total,Percentage100,10,1.4640,2,.3800,314,45.41024,319,46.11280,46,6.71600,2,.32048,4,.6Edited by - SamC on 12/05/2002 12:45:09Edited by - SamC on 12/05/2002 12:45:51 |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-12-05 : 18:39:07
|
| CREATE TABLE #Res ( width int, height int )CREATE TABLE #Clients ( clientid int, width int, height int )INSERT INTO #Res (width, height) VALUES (640,480)INSERT INTO #Res (width, height) VALUES (800,600) INSERT INTO #Res (width, height) VALUES (1024,768) INSERT INTO #Res (width, height) VALUES (1280,1024) INSERT INTO #Res (width, height) VALUES (1400,1050) INSERT INTO #Res (width, height) VALUES (1600,1200)INSERT INTO #Clients (clientid, width, height) VALUES (1,640,452) INSERT INTO #Clients (clientid, width, height) VALUES (2,759,556) INSERT INTO #Clients (clientid, width, height) VALUES (3,759,565)INSERT INTO #Clients (clientid, width, height) VALUES (4,759,565) SELECT reswidth, resheight, Count(*) AS Total, CAST(Count(*) * 100.0 / (SELECT COUNT(*) FROM #Clients) AS NUMERIC(5,1)) as Percentage FROM(SELECT A.clientID, MIN(A.awidth) clientwidth, MIN(A.aheight) clientheight, MIN(A.bwidth) reswidth, MIN(A.bheight) resheightFROM(SELECT A.clientid, b.width bwidth, a.width awidth, b.height bheight, a.height aheightFROM #Clients A CROSS JOIN #Res BWHERE b.width >= a.width AND b.height > = a.height) AGROUP BY A.ClientID) AGROUP BY reswidth, resheightDROP TABLE #ResDROP TABLE #ClientsEdited by - ValterBorges on 12/05/2002 18:39:30 |
 |
|
|
|
|
|