473,395 Members | 1,766 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,395 software developers and data experts.

How I get query for Using divide each of 2 rows

I have a data like this,
Data1 Data2
35 30
25 10
40 20

I want 3rd column for display like this,
Data1 Data2 Data3
35 30 (default=0)
25 10 (30-10)
40 20 (10-20 )
.. .. [(1st row of Data2)-(2nd row of Data2)]

how I get the query or VB for resolve this proble
thank you
Jul 3 '08 #1
3 1353
FishVal
2,653 Expert 2GB
Hello.

How a row could be recognized as a previous one?
Or rephrasing the question: do you have a primary key field in the table or at least any unique field?

Regards,
Fish.
Jul 3 '08 #2
I have a record is
Date Batch No. data final
12/1/2007 THDA008261 76000
15/1/2007 THDA008262 74400
25/1/2007 THDA008313 158000
26/1/2007 THDA008314 54400
26/1/2007 THDA008315 55600

primary key is Batch No.
I want a new coloum of the query to display like this

Date Batch No. vis final Diff data
12/1/2007 THDA008261 10 0
15/1/2007 THDA008262 50 40
25/1/2007 THDA008313 20 -30
26/1/2007 THDA008314 60 40
26/1/2007 THDA008315 20 -40

Regards,
kran
Jul 3 '08 #3
FishVal
2,653 Expert 2GB
I have a record is
Date Batch No. data final
12/1/2007 THDA008261 76000
15/1/2007 THDA008262 74400
25/1/2007 THDA008313 158000
26/1/2007 THDA008314 54400
26/1/2007 THDA008315 55600

primary key is Batch No.
I want a new coloum of the query to display like this

Date Batch No. vis final Diff data
12/1/2007 THDA008261 10 0
15/1/2007 THDA008262 50 40
25/1/2007 THDA008313 20 -30
26/1/2007 THDA008314 60 40
26/1/2007 THDA008315 20 -40

Regards,
kran
Hi, kran.

First and for most, that is a kind of task a spreadsheet (like Excel) could do more effectively.
  • Using spreadsheet approach you may export the dataset (appropriately ordered) to Excel and add formula to calculate differences.
  • Though it is possible with a query (table self-join on batch number from a first alias is the next one to that from a second alias), it could take a long time for the query to run. As far as I could recall a much more light join logic (number comparisson instead of number containing string comparisson) took several hours to run on 50k records table. How many records do you have in the table?

Second point is about how batch numbers are supposed to be compared:
  • Does a greater number in a batch number always mean the batch number is greater?
  • Does batch number always start from "THDA"?
  • Does batch number always start from fix-width symbol combination?
  • Any other points from you concerning batch number comparisson.

Regards,
Fish
Jul 3 '08 #4

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

Similar topics

13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
2
by: Lin Ma | last post by:
Greetings, In my search application, user can type a number to search. I use LIKE in my query. If a query result generates over 10,000 recordsets, it may several minutes to run. Is there a...
4
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table...
14
by:  | last post by:
having a spot of trouble writing this one. if you are so inclined and have a moment, i'd really appreciate your insight. i have what amounts to a purchase order type of setup...a descriptive...
13
by: Dmitry Tkach | last post by:
Hi, everybody! Here is a weird problem, I ran into... I have two huge (80 million rows each) tables (a and b), with id as a PK on both of them and also an FK from b referencing a. When I try to...
6
by: Steven D.Arnold | last post by:
I have a query which does not use column indexes that it should use. I have discovered some interesting behaviors of Postgres which may indicate a bug in the database's query planning. Take a...
0
by: Gary Carson | last post by:
Can anyone tell why the query below would throw a divide-by-zero error? The only reason I can see for the error happening would be if SUM() came out to be zero, but this never happens with the...
5
by: Otie | last post by:
I have a select query that groups records together, specifically baseball players and their home runs and at-bats. I want to create a query that displays , , and and that sorts ASCENDING on the ...
21
by: CSN | last post by:
I have a pretty simple select query that joins a table (p) with 125K rows with another table (pc) with almost one million rows: select p.* from product_categories pc inner join products p on...
3
by: bob laughland | last post by:
Hi All, I have a SQL query like this (I have tried to break the problem down to simplify it), select rowid from table where name in ('a', 'b', 'd') group by rowid Here is an example of data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
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...

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.