473,465 Members | 4,818 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

compare in database

8 New Member
I get a table with the following query
select k.sifrakolo as Id,j.jb1,d.jb2,t.jb3,c.jb4,p.jb5,s.jb6
from
kolo k,jedan j, dva d, tri t, cetiri c, pet p, sest s
where
k.b1 = j.b1 and
k.b2 = d.b2 and
k.b3 = t.b3 and
k.b4 = c.b4 and
k.b5 = p.b5 and
k.b6 = s.b6
How do I use query to get 3 same tables t1,t2,t3 with
t2 = t1.id -1 and
t3 = t1.Id -2
and compare data in t1 and t2 as p1 and
compare data in t1 and t3 as p2 as follows
SELECT

cast(case when t1.jb1 = t2.jb1 then '1' else '0' end as int)+
cast(case when t1.jb2 = t2.jb2 then '1' else '0' end as int)+
cast(case when t1.jb3 = t2.jb3 then '1' else '0' end as int)+
cast(case when t1.jb4 = t2.jb4 then '1' else '0' end as int)+
cast(case when t1.jb5 = t2.jb5 then '1' else '0' end as int)+
cast(case when t1.jb6 = t2.jb6 then '1' else '0' end as int)as p1,

cast(case when t1.jb1 = t3.jb1 then '1' else '0' end as int)+
cast(case when t1.jb2 = t3.jb2 then '1' else '0' end as int)+
cast(case when t1.jb3 = t3.jb3 then '1' else '0' end as int)+
cast(case when t1.jb4 = t3.jb4 then '1' else '0' end as int)+
cast(case when t1.jb5 = t3.jb5 then '1' else '0' end as int)+
cast(case when t1.jb6 = t3.jb6 then '1' else '0' end as int)as p2

order by t1.sifrakolo desc
Feb 8 '07 #1
1 1270
iburyak
1,017 Recognized Expert Top Contributor
[PHP]SELECT
case when t1.jb1 = t2.jb1 then 1 else 0 end +
case when t1.jb2 = t2.jb2 then 1 else 0 end +
case when t1.jb3 = t2.jb3 then 1 else 0 end +
case when t1.jb4 = t2.jb4 then 1 else 0 end +
case when t1.jb5 = t2.jb5 then 1 else 0 end +
case when t1.jb6 = t2.jb6 then 1 else 0 end as p1,

case when t1.jb1 = t3.jb1 then 1 else 0 end +
case when t1.jb2 = t3.jb2 then 1 else 0 end +
case when t1.jb3 = t3.jb3 then 1 else 0 end +
case when t1.jb4 = t3.jb4 then 1 else 0 end +
case when t1.jb5 = t3.jb5 then 1 else 0 end +
case when t1.jb6 = t3.jb6 then 1 else 0 end as p2
FROM t1
join t2 on t2.id = (t1.id - 1)
join t3 on t3.id = (t1.id - 2)
order by t1.sifrakolo desc[/PHP]
Feb 8 '07 #2

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

Similar topics

3
by: Stephen | last post by:
I have to write a .Net application which can compare SQL Databases including things like: - DB structure, PK's, FK's, indexes and types of indexes i.e. should be able to detect if the same index...
1
by: serge | last post by:
Can someone recommend what SQL Database compare tool to use and why? Thank you
2
by: serge | last post by:
Is there a way to compare two databases one being an old database and the second being a new database, I will update the old database's objects to match the new database's objects? Is there SQL...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
4
by: Sunit Joshi | last post by:
Hello All I'm trying to figure out how to do this the best way. Basically, I need to compare DateTime of files across TimeZones. The situation is like this: 1. I have a database say in Korea...
4
by: Gaby | last post by:
Hi all, What is the best way to compare 2 (large) ArrayLists filled with an object. Can you please help me? Gaby
3
by: Benny Ng | last post by:
Dear all, The following is the source. The password is encrypted and saved into the Binary in SQL2K. Now I want to create a new page to compare the existed password and the password that in the...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
0
by: dingo | last post by:
DBC ensuring your applications don't fail due to a missing database structure object.DBC (Database Compare) is a fast, comprehensive database structure and data comparison tool.Sort sync scipts...
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
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
Oralloy
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,...
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.