Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Inline queries
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Inline queries

 Post Reply Post Reply
Author
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Topic: Inline queries
    Posted: 12 August 2004 at 5:56am

Hi, I am writing a stored procedure and trying to do an inline query on the same table:

ALTER PROCEDURE djLink_sp_GetBrowserStats

AS

Declare @TotalBrowsers int

Select @TotalBrowsers = Count(*) From djLink_tblBrowsers

Select

Distinct

BrowserName,

(Select Count(*) From djLink_tblBrowsers Where BrowserName = djLink_tblBrowsers.BrowserName) As Total,

((Select Count(*) From djLink_tblBrowsers Where BrowserName = BrowserName) / @TotalBrowsers * 100) As Percentage

From

djLink_tblBrowsers

The problem is on this line (and the line preceeding):

(Select Count(*) From djLink_tblBrowsers Where BrowserName = djLink_tblBrowsers.BrowserName) As Total

Basically because I am doing the query in the same table it is getting confused and counting all rows, not just ones with the same browser name.

Is there anyway to get around this?

Thanks, Mart.

Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 12 August 2004 at 9:31am


Declare @TotalBrowsers int

Select @TotalBrowsers = Count(*) From djLink_tblBrowsers

Select

BrowserName,

(Select Count(*) From djLink_tblBrowsers Where BrowserName = djLink_tblBrowsers.BrowserName) As Total,

((Select Count(*) From djLink_tblBrowsers Where BrowserName = BrowserName) / @TotalBrowsers * 100) As Percentage

From

djLink_tblBrowsers

Group by BrowserName

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 12 August 2004 at 10:47am
Hmm didn't seem to work, same outcome.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 12 August 2004 at 11:33am

Heres a little more info:

The data in djLink_tblBrowsers:

BrowserName        & nbsp;         & nbsp;         & nbsp;         & nbsp; Platform        &nbs p;         &nbs p;         &nbs p;         &nbs p;    Javascript  Cookies     Crawler    
-------------------------------------------------- -------------------------------------------------- ----------- ----------- -----------
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
Netscape 5.0         &nb sp;         &nb sp;         &nb sp;         WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP         & nbsp;         & nbsp;         & nbsp;         & nbsp;      1           ; 1           ; 0
IE 6.0         &nb sp;         &nb sp;         &nb sp;         &nb sp;     WinXP   

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 12 August 2004 at 11:34am
The RTE didn't like that but you get the point
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 12 August 2004 at 12:03pm

I got it to work:

Declare @TotalBrowsers int
Select @TotalBrowsers = Count(BrowserName) From djLink_tblBrowsers

Select
 Distinct
 BrowserName,
 Count(BrowserName) As Total,
 Count(BrowserName) * 100 / @TotalBrowsers As Percentage
From
 djLink_tblBrowsers
Group By
 BrowserName

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.