SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 15th, 2004, 04:52 PM
LilMoke LilMoke is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 LilMoke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool SQL Query question...

Hello,

I am trying to do a query on the data below and produce the following report:

Win 95 5
Win 98 8
Win NT 4.0 3
Win NT 5.0 9
Win NT 5.2 20

I am not quite sure how to do a query that contains all the counts. I can do this:

SELECT COUNT(*) FROM dbo.Log WHERE [logField] LIKE '%User Agent:%Windows 95%'

And that works, but I am not sure how to do it for all the platforms. The other caveat is that
the data type is ntext, so I think I need to do something like:

SELECT SUBSTRING(text, 0, 128) AS Expr1, COUNT(*) etc.

I am not an expert at SQL, but understand it well enough to do somewhat complex queries, but
this one has me stumped.

Any help would be greatly appreciated.

The field format:

User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; (R1 1.5))
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; (R1 1.5))
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; (R1 1.5))
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
User Agent: Mozilla/5.0
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 95; Supplied by blueyonder)
User Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 95; Supplied by blueyonder)
User Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 95; Supplied by blueyonder)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; GTE_IE4; Hotbar 3.0)
User Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 5.13; Mac_PowerPC)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; libero)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
User Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
User Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
User Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; (atfile.com))

Thank you,
Tony

Reply With Quote
  #2  
Old June 15th, 2004, 06:21 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 18 h
Reputation Power: 500
You should split the value first to retrieve the OS, then insert that into a different field, then your select statement would be something like this
Code:
SELECT OS, COUNT(*) As 'Count'
FROM TableName
GROUP BY OS
ORDER BY 'Count' DESC

Reply With Quote
  #3  
Old June 16th, 2004, 02:06 AM
LilMoke LilMoke is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 LilMoke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Yes, that is one option I thought of. However, I already have this data in a table and it contains
thousands of records. Rather than writing code to 'fix-up' the already existing records, I was
hoping I could perform an SQL query to do the job.

Any other ideas/options?

Thanks for your assistance,
Tony

Reply With Quote
  #4  
Old June 16th, 2004, 10:23 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 18 h
Reputation Power: 500
What you could do is create another field called OS.
Extract the OS from the text string and update the OS field with the extracted value, then do a distinct count on that field.

Last edited by Memnoch : June 16th, 2004 at 10:26 AM.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > SQL Query question...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT