Unusal group by interval(x) ordering

Post Reply
bart
Posts: 251
Joined: Wed Apr 26, 2000 12:42 am

Unusal group by interval(x) ordering

Post by bart »

Why when I execute the query below is the output order unusual? I know it's supposed to have an 'order by' if I really wanted it in order, but I'm curious.

tsql "select avg(Cnt),Ldate from sitelog where Service='' and Site='www' group by month(Ldate)"

avg(Cnt) Ldate
19085 2001-01-01 00:00:00
18445 2001-02-01 00:00:00
52 2000-05-08 00:00:00
13268 2000-06-04 00:00:00
17436 2000-07-01 00:00:00
20505 2000-08-01 00:00:00
15232 2000-09-01 00:00:00
19867 2000-10-01 00:00:00
16005 2000-11-01 00:00:00
14709 2000-12-01 00:00:00
User avatar
John
Site Admin
Posts: 2621
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Unusal group by interval(x) ordering

Post by John »

As you mention the ordering is undefined unless you specify an order by. In the case of the group by the results are often ordered by what you are grouping by, in this case month(Ldate), so it is not particularly unusual.
John Turnbull
Thunderstone Software
Faiz
Posts: 109
Joined: Wed Jan 10, 2001 1:29 pm

Unusal group by interval(x) ordering

Post by Faiz »

Hi,
I am getting erroneous results when I do a group by on a varchar field.
My query is,
select keywords, count(*) from query_log
group by keywords
order by 2 desc
some of the results show,
keywords count(*)
------------+------------+
felix the cat 422
production server 347
deburring 283
corporate store 244
..........

but when i do a count(*) on the above keywords, I get only 1. why am I getting such huge values?
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Unusal group by interval(x) ordering

Post by Kai »

What is the exact query you're using to do the count(*) on a given keyword set? Also, what version of texis is this (entire output of texis -version)?
Faiz
Posts: 109
Joined: Wed Jan 10, 2001 1:29 pm

Unusal group by interval(x) ordering

Post by Faiz »

ok, my query was,
select count(*) from query_log where keywords='production server'
AND
the result was,
count(*)
------------+
1
The "group by" showed it as 347.
i ran it on the version,
Texis Web Script (Vortex) Copyright (c) 1996-2000 Thunderstone - EPI, Inc.
Commercial Version 3.01.975518872 of Nov 29, 2000 (sparc-sun-solaris2.6)
but I do have a latest version,
Texis Web Script (Vortex) Copyright (c) 1996-2001 Thunderstone - EPI, Inc.
Commercial Version 3.01.987613528 of Apr 18, 2001 (sparc-sun-solaris2.6)

Both the versions are giving erroneous results.

Regards,
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Unusal group by interval(x) ordering

Post by Kai »

We can't replicate the problem with either version. What indexes, if any, are there on query_log, in particular on keywords? If you try the query without the "order by " what are the results?
Faiz
Posts: 109
Joined: Wed Jan 10, 2001 1:29 pm

Unusal group by interval(x) ordering

Post by Faiz »

Basically, I am logging all the keywords entered for search, by users, in a log file. I want to find out the queries which are searched most in a particular month. What I did was imported all the data from the log file into the table query_log (id counter, keywords varchar(200)) using the timport functionality.
I imported the data after removing the leading and trailing spaces and coverting all of them to lower case.
There are no indexes in the table. Then i wanted to find out the number of times each distinct query occured in the table using the sql query with group by clause. That is when I got improper results.
I am also doing a group by on an integer field in one of my programs and there is no problem in that.
Faiz
Posts: 109
Joined: Wed Jan 10, 2001 1:29 pm

Unusal group by interval(x) ordering

Post by Faiz »

I dont know why, but when I added a where clause, it seemed to work ok. This was the query which did ok,
select count(*), keywords from query_log
where keywords matches 'a%' or keywords matches 'b%'
.......
group by keywords
order by 1 desc
Post Reply