473,809 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug in queries ??

Hi all,
I have three questions about 1 table

CREATE TABLE public.logs
(
rule_name varchar(32) NOT NULL,
bytes int8 NOT NULL,
pkts int8 NOT NULL,
hostname varchar(100),
that_time int4 NOT NULL
) WITH OIDS;

Question 1.

If I run the following query:

select cast(min(that_t ime) as abstime), cast(max(that_t ime) as abstime), (sum(bytes)/(1024*1024)) as "Totaal in Megabytes" from logs
where
that_time between cast( abstime('2004-10-1 00:00') as int4) and cast( abstime('2004-11-1 00:00') as int4)
and
rule_name = 'Incoming 83 50 in' or
rule_name = 'Outgoing 83 50 out'

I expect that the outcome will be between "2004-10-1 00:00" and "2004-11-1 00:00" (the month october). However, I get the following result:

min max Totaal in Megabytes
"2004-09-01 00:00:01+02" "2004-11-23 11:50:01+01"; "82768.62335300 4456"

The min date is the date of the first entry ever, the max entry the last entry ever. Why is this?
Question 2.

If I refrase the above query to:

select cast(min(that_t ime) as abstime), cast(max(that_t ime) as abstime), (sum(bytes)/(1024*1024)) as "Totaal in Megabytes" from logs
where
rule_name = 'Incoming 83 50 in' or
rule_name = 'Outgoing 83 50 out'
and
that_time between cast( abstime('2004-10-1 00:00') as int4) and cast( abstime('2004-11-1 00:00') as int4)

I get a diffent answer (see the Totaal in Megabytes):

min max Totaal in Megabytes
"2004-09-01 00:00:01+02" "2004-11-23 12:00:01+01" "92406.07844448 0896"

My question why is this?

Question 3.

Querying for just "rule_name = 'Incoming 83 50 in'" gives 34990 Megabytes, just querying for "rule_name = 'Outgoing 83 50 out'" gives 5524 Megabytes. How does that compare to the queries above?
Groeten,

Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
e-mail: J.***********@A skesis.nl
web: www.askesis.nl

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #1
2 2110
Joost Kraaijeveld wrote:

If I run the following query:

select cast(min(that_t ime) as abstime), cast(max(that_t ime) as abstime), (sum(bytes)/(1024*1024)) as "Totaal in Megabytes" from logs
where
that_time between cast( abstime('2004-10-1 00:00') as int4) and cast( abstime('2004-11-1 00:00') as int4)
and
rule_name = 'Incoming 83 50 in' or
rule_name = 'Outgoing 83 50 out'


Do brackets solve your problem?

WHERE that_time betweeen ...
AND (
rule_name = ...
OR rule_name = ...
)

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #2
"Joost Kraaijeveld" <J.***********@ Askesis.nl> wrote:

Hi all,
I have three questions about 1 table

CREATE TABLE public.logs
(
rule_name varchar(32) NOT NULL,
bytes int8 NOT NULL,
pkts int8 NOT NULL,
hostname varchar(100),
that_time int4 NOT NULL
) WITH OIDS;

Question 1.

If I run the following query:

select cast(min(that_t ime) as abstime), cast(max(that_t ime) as abstime),
(sum(bytes)/(1024*1024)) as "Totaal in Megabytes" from logs
where
that_time between cast( abstime('2004-10-1 00:00') as int4) and
cast( abstime('2004-11-1 00:00') as int4)
and
rule_name = 'Incoming 83 50 in' or
rule_name = 'Outgoing 83 50 out'

I expect that the outcome will be between "2004-10-1 00:00" and
"2004-11-1 00:00" (the month october). However, I get the following result:

min max Totaal in Megabytes
"2004-09-01 00:00:01+02" "2004-11-23 11:50:01+01"; "82768.62335300 4456"

The min date is the date of the first entry ever, the max entry the
last entry ever. Why is this?
Because you're asking "between 1st date and second date and rule_name
equals something," OR rule_name equals something_else.

What you have is equivilent to

where (that between ... and ... and rule = ...) or rule = ...

You want

where time between ... and ... and (rule = ... or rule = ...)


Question 2.

If I refrase the above query to:

select cast(min(that_t ime) as abstime), cast(max(that_t ime) as abstime),
(sum(bytes)/(1024*1024)) as "Totaal in Megabytes" from logs
where
rule_name = 'Incoming 83 50 in' or
rule_name = 'Outgoing 83 50 out'
and
that_time between cast( abstime('2004-10-1 00:00') as int4) and
cast( abstime('2004-11-1 00:00') as int4)

I get a diffent answer (see the Totaal in Megabytes):

min max Totaal in Megabytes
"2004-09-01 00:00:01+02" "2004-11-23 12:00:01+01" "92406.07844448 0896"

My question why is this?
You have

where rule = ... or (rule = ... and time between ...)

Question 3.

Querying for just "rule_name = 'Incoming 83 50 in'" gives 34990
Megabytes, just querying for "rule_name = 'Outgoing 83 50 out'" gives
5524 Megabytes. How does that compare to the queries above?


The answer is probably clear by now ;).

Jim

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6788
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used the SQL Profile to watch the T-SQL-Command which Access ( who creates the commands?) creates and noticed:
5
3722
by: WertmanTheMad | last post by:
Ive been playing with this for a few days and thought I might thow it out for seggestions. I have Several Queries that need counts returned The Queries are Mutually Exclusive meaning whatever Query they return in first they cannot be included in the counts of any queries below them. This set of queries for example
1
2320
by: Roger Green | last post by:
I have inherited a complex database that has many dozens of queries that derive data from a people table. I now need to be able to run these queries (from within a significant number of forms) not on the full dataset, but on a subset of the data in the people table. I want to avoid having to put criteria in all of the individual queries or forms, or having to change the data source for all the queries. Is there anyway I can restrict...
9
4362
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
3
2337
by: NeilAnderson | last post by:
I'm a fairly new user of access & I've never had any training, so I'm wondering if I'm doing the right thing here, or if it matter at all. I'm building a database for room booking purposes and I'm trying to do all record changing using queries. From what I can glean from this (excellent!) group this is the right way to go about it. At present what I'm doing is building & trouble-shooting the queries with query-builder then using code to...
5
4046
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I think - it might have been XP) to 2003. The database is impressive, both in what it does and the obtuse and inconsistent ways it works. There are several hundred queries, for example, with no indication of where they are used or if they are in fact...
0
8781
by: MHenry | last post by:
Hi, I know virtually nothing about creating Macros in Access. I would appreciate some help in creating a Macro or Macros that automatically run(s) 14 Queries (three Make Table Queries, and 11 Append Queries) when the Database is first opened, and then again anytime I invoke the Macro (somehow) after the database is already open. The latter function is useful, because the queries must be rerun every time data is added, deleted, or...
44
4577
by: Greg Strong | last post by:
Hello All, Is it better to create a query in DAO where a report has 4 sub-reports each of whose record source is a query created at runtime and everything is in 1 MDB file? From what I've read and experienced it appears DAO is the way to go in this situation, so when is it good to use ADOX to create queries? Why do I ask the question? I've created a MDB file which uses DAO, but
1
2099
by: loosecannon_1 | last post by:
Hello everyone, I am hoping someone can help me with this problem. I will say up front that I am not a SQL Server DBA, I am a developer. I have an application that sends about 25 simultaneous queries to a SQL Server 2000 Standard Edition SP4 running on Windows 2000 Server with 2.5 GB of memory. About 11 of these queries are over views (all over the same table) and these queries are all done from JDBC but I am not sure that matters. ...
5
6330
by: marshmallowww | last post by:
I have an Access 2000 mde application which uses ADO and pass through queries to communicate with SQL Server 7, 2000 or 2005. Some of my customers, especially those with SQL Server 2005, have had pass-through queries fail due to intermittent connection failures. I can easily restablish a connection for ADO. My problem is with pass-through queries.
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.