Hello bytes,
Im playing around abit with graphs in access 2007 and i would need to visualise the diffrence rather then the total;
for example if the total if 100 year one, 120 year two and 150 year three i would like the graph to be ,(1,0) (2,20) (3,30). Scince the graphs are based on quaries i though it would be simple to add a delta column but I find it easier said than done and im stuck.
So what am I trying to do, Im trying to create a column which get the value from its row and subract it with the value from the row before (except the first year which need to be 0)
heres the sql statement i got so far -
SELECT PrivatePropertyMarketMDB.Statistic AS SQLSMÅHUS, PrivatePropertyMarketMDB.PubDate, MunicipalityMDB.Municipality, MunicipalityMDB.MunicipalityCode
-
FROM MunicipalityMDB INNER JOIN (DevelopmentTypeMDB INNER JOIN PrivatePropertyMarketMDB ON DevelopmentTypeMDB.DevType_id = PrivatePropertyMarketMDB.DevelopmentType) ON MunicipalityMDB.Municipality_ID = PrivatePropertyMarketMDB.Municipality
-
WHERE (((DevelopmentTypeMDB.DevelopmentType)="småhus"));
-
If anyone have any tip of what to do or know any article which could help i would be grateful!
9 2067
I can't comment too much on your SQL because you haven't told us what your table design looks like but I can offer general advice.
You will need to join the table to itself so that you can get the previous year's data so that you can calculate the delta. It will have to be an outer join because the first year will not have a previous year to join to. You will need to handle the resulting Null using the Nz function.
NeoPa 32,556
Expert Mod 16PB Tabasco:
Scince the graphs are based on quaries i though it would be simple to add a delta column but I find it easier said than done and im stuck.
That would be wrong thinking indeed. Database work is all based on Set Theory. There is no concept of juxtaposition (or relative order) within Set Theory. That's a way of thinking you would benefit greatly from leaving behind.
@NeoPa, well, I don't know about leaving it behind. Perhaps leave behind the idea of it being easy to compare between records in SQL. But not leaving behind the idea of ever comparing between records in SQL.
If the requirement the customer wants is to graph the deltas, I don't know how they would feel about hearing that they shouldn't because it's not in line with set theory.
NeoPa 32,556
Expert Mod 16PB
Indeed. I believe I was quite specific in referring to the way of thinking though.
As you so correctly imply, many things can be achieved in Access, even if they are conceptually foreign to the whole concept of RDBMSs. I do believe though, that the whole way of thinking (that can probably be best explained by thinking of Access as Excel) is quite detrimental to doing work within an RDBMS (of any variety). This thinking (to my mind at least) was illustrated quite clearly in the short excerpt I quoted in my post.
Letting go of that would certainly be of great benefit to the OP (Like leaving behind a ruck-sack full of bricks on a hike). Until they do let go, it will only weigh them down.
Thank you both for the useful and insightful tip,
I got it working evantually and I'll write the code if someone else hase the same problem of course you cant copy it but it might serve as a step in the wright direction -
SELECT t2.date AS Expr1, t2.TABLE-t1.TABLE AS Delta,
-
FROM [TABLE] AS t2 INNER JOIN [TABLE] AS t1 ON t2
-
WHERE (((t2.date)=DateAdd("yyyy",1,[t1].[pubdate])));
-
The access graph tool visualize the SQL statement so I have to get a SQL to show delta because im trying to avoid Excel completely. It much more simple to use excel to get the deltacolumn however it wast so hard in access either once I knew how to do it.
Thanks again for the help!
I noticed you used an inner join instead of the outer join I suggested. Do you not need the first year? If you do, you'll have to use an outer join.
Yes i need the first entry and, i tried to use outer join directly in the first sqlstatement but it didnt work, in access you seem to have to use "FULL OUTER JOIN", "LEFT OUTER JOIN" and "RIGHT OUTER JOIN" I tried all three but it seems not to give the result i need.
However i use it later because i also have a sqlstatement which calculate the total for evervy entry (So i get every row) so I join this statement whith the other statement with an outerjoin, I just posted the sqlstatement for which i got the deltacolumn.
But I works kind of slow maybe it will be faster if I'm able to use the outer join directly?
PS I used IIF(ISNULL(DELTA); DELTA; 0) mainly because of old habits instead of NZ() function maybe thats slowing it down DS
You have to use a left outer join. And your where condition needs to be in the join. You can use the IIF or the NZ, I doubt if one will be significantly faster than the other. NZ is probably only slightly faster.
NeoPa 32,556
Expert Mod 16PB Rabbit:
your where condition needs to be in the join
Further to Rabbit's comment - the ON section of the JOIN needs to be specified to select the required records only. Your code : - FROM [TABLE] AS t2 INNER JOIN [TABLE] AS t1 ON t2
... is incorrectly formatted. I don't even know how it worked, but I expect it simply treats it as TRUE. This would produce a Cartesian Product (At this point see SQL JOINs.) which makes sense when using a WHERE clause, but would be expected to run relatively slowly.
Instead of using this particular WHERE clause, you should specify the logic using ON, such as : - SELECT t1.Date
-
, t1.Table-t2.Table AS Delta
-
FROM [TABLE] AS t1 LEFT JOIN [TABLE] AS t2
-
ON t1.Date=DateAdd('yyyy',1,t2.PubDate)
Having now looked at your SQL in more detail it is clear that it has never run as you posted it. It had some serious syntactical errors in it that no SQL engine could run.
You should also be aware that, as a function is integrally involved in the selection of records, this SQL will run slower than if that were not the case. Faster than the same code in the WHERE clause hopefully, but nevertheless not top speed for SQL. I don't see a way of avoiding this. Even if each record represents a separate year there would still be some level of function call required to determine which records matched which.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Eugene |
last post by:
Hello All,
I need a report in Access 2007 to show a dynamic image on every page.
I have a table, and I store image's path in a cell in each of the
rows.
In 2003, I was able to do that using...
|
by: ARC |
last post by:
This is taken from the "What's New in Access 2007" page. However, I've
looked through all the properties of a text field memo box, and cannot find
the append only option. Does anyone know how to...
|
by: Kev |
last post by:
Hello,
Can someone tell me if Access 2007 can wrap the datasheet column
heading like Excel does?
I know I can do it in continuous form view but I would prefer to use a
datasheet.
Am wondering...
|
by: haniss |
last post by:
After importing a txt delimited file into Access 2007 with adding Couonter
there is a problem with column order. For example in txt file:
John|Doe|25.10.2007
in new Access table are 4...
|
by: anthony |
last post by:
In Access 2007, why does a query field designed as Term: !
! return 00:00:00 when cboTerm actually contains
08SP. This works as expected in Access 2003?
|
by: curran.george |
last post by:
'add one textbox to form1 with Control Source property = ID
'copy/paste the form_load code below:
'Then open the form and then attempt to sort the datasheet
'crashes 2003, error 3450 Access 2007 -...
|
by: prakashwadhwani |
last post by:
Hi !! I'm about to develop a new project for a client.
Should I go about it in Access 2003 or 2007 ? Purchasing it either
for me or for my client is not a major consideration here ... what I'd...
|
by: khoward |
last post by:
Hi,
I have an Access 2007 database that contains customer contact information. There are over 8,000 that include name, organization (as a look-up column), email, phone, address, and events that...
|
by: Lina Arraiz |
last post by:
First of all, my apologies for originally posting this question in the wrong section. I'm trying to export an Excel 2003 spreadsheet to Access 2007. Column D (START) has the start time and Column E...
|
by: prashantdixit |
last post by:
Hi,
I have beent trying importing Excel data with one column containing PDF/JPEG file name to access 2007.
I have a Excel file with few columns
One of the columns named as "Reference". The...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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...
| |