473,413 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

How to detect differencess/similarities between Rows in Tables

119 100+
I have a table that stores date/value pairs. The dates are successive end-of-month values.

For each month, I need to know if
(1) a value is not present, but was in the previous month (e.g. a "sell")
(2) a value is present, but was not in the previous month (e.g. a "buy")
(3) a value was present for both months (e.g. a "keep" of that value)

e.g.

12/31/2014 A
12/31/2014 B
01/31/2015 A
01/31/2015 C

For date 1/31/2015

(1) B is not present, but was previously (e.g. a "sell")
(2) C is present, but wasn't previously (e.g. a "buy")
(3) A is present in this and the previous month (e.g. a "keep")

I have been able to achieve this, but I believe in a reasonably inefficient way. My method was:

(1) Create a query with date/value pairs, but date shifted forward by a month (using a VBA function): qryD2
(2) Perform separate inner/outer joins on the original table and qryD2, joining on the date fields.

e.g. qryD2

Expand|Select|Wrap|Line Numbers
  1. SELECT NextMonth([tblValues.dt]) AS dtNext, tblValues.Value
  2. FROM tblValues;
e.g. to return the "sells"

Expand|Select|Wrap|Line Numbers
  1. SELECT qryD2.dtNext AS dt, qryD2.Value, 'S' as Type
  2. FROM tblValuesRIGHT JOIN qryD2 ON (tblValues.dt = qryD2.dtNext) AND (tblValues.Value= qryD2.Value)
  3. WHERE (((tblValues.Value) Is Null)) OR (((qryD2.Value) Is Null));
Is there a more efficient way to do this, or is this pretty much it?
Feb 12 '15 #1
1 904
Rabbit
12,516 Expert Mod 8TB
That's the correct approach.
Feb 12 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Marcus | last post by:
Hello, I recently converted all my existing MyISAM tables to InnoDB tables through phpmyadmin. I noticed some strange behavior whenever I would refresh the screen, as phpmyadmin would report...
3
by: Bill Tepe | last post by:
I have a need to insert rows into an Audit type table when values change in certain fields in a table. I thought I could do this via a trigger. However, on requirement is to include in the audit...
19
by: jim | last post by:
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid If IsDBNull(Clinics.Clinics.Item(A).Workphone) The <other code End I Clinics.Clinics is a dataset that...
32
by: Toby Inkster | last post by:
http://examples.tobyinkster.co.uk/inc_dt.phps -- Toby A Inkster BSc (Hons) ARCS Contact Me ~ http://tobyinkster.co.uk/contact
2
by: Molly | last post by:
Does anyone know of any good tools for fast, on-line reorgs of a very large DB2 UDB table? We need to reorg a couple of our large (+1 billion rows) tables. We migrated from V7.2 to V8.1, but we...
7
by: who be dat? | last post by:
I need some help here. I'm creating a list on a page where the list is created from a dataset with two tables linked with a datarelation. The first table is a list of groups while the second...
2
by: eBob.com | last post by:
I've got the basics of an XML ini file working. I.E. I can stash away and retrieve user preferences. (Code below.) But how do I handle a new preference? Say I have A and B. And then I invent...
5
by: phillip.s.powell | last post by:
$sql = "SELECT IF((SHOW TABLES LIKE '$subselectTableName'), count(*), NULL) AS numRows FROM $subselectTableName"; I am trying to write a SQL statement that will tell me if a table exists or not,...
6
sumittyagi
by: sumittyagi | last post by:
Hi! to all! I have got an issue. * I maintain serial no. of rows tables in a column serial_no(which is set as primary key). * while inserting i count the no of rows, "select count(*) from...
2
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I have a gridview with paging enabled. I need to know how many rows of data are on the last page!!! When I look at the Gridview1.Rows.Count in the Page_Load, it always returns the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.