need query advice

Поиск
Список
Период
Сортировка
От Stephan Fiebrandt
Тема need query advice
Дата
Msg-id 4170E524.2040101@kuehlbox.de
обсуждение исходный текст
Ответы Re: need query advice
Список pgsql-sql
Hello all,

i've got a psql database, with a table including 6 rows named "zahl1 
zahl2 zahl3 zahl4 zahl5 and zahl6" type integer

There are about  10.000 entries in the table. In every entry, the 
numbers are uniq to each other. That means, if zahl1=1, then zahl2-6 
cannot be also 1. Example:

1, 10, 78, 43, 2, 67              (all 6 numbers are different in the 
same line, never a dup)
56, 34, 78, 1, 77, 99            (but repeating in the db tousand times 
of course)
1, 2, 3, 4, 5, 6
2, 3, 4, 99, 5, 6
...


$a ... $f are the variables, of the 6 numbers i am searching: The 
numbers that are given to search, are also uniq of course, or it would 
not make sense.
I need all hits, where at leased 5 of the given 6 numbers are maching in 
every entry:


select * from zaehlerzuordnung_snapshots where ((zahl1=$a or zahl2=$a or 
zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) and (zahl1=$b or zahl2=$b 
or zahl3=$b or zahl4=$b or zahl5=$b or zahl6=$b) and (zahl1=$c or 
zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c or zahl6=$c) and (zahl1=$d 
or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d or zahl6=$d) and 
(zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or zahl5=$e or zahl6=$e))

or

((zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or zahl6=$b) 
and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c or 
zahl6=$c) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d 
or zahl6=$d) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or 
zahl5=$e or zahl6=$e) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f 
or zahl5=$f or zahl6=$f))

or

((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) 
and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c or 
zahl6=$c) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d 
or zahl6=$d) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or 
zahl5=$e or zahl6=$e) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f 
or zahl5=$f or zahl6=$f))

or

((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) 
and (zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or 
zahl6=$b) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or zahl5=$d 
or zahl6=$d) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or 
zahl5=$e or zahl6=$e) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f 
or zahl5=$f or zahl6=$f))

or

((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) 
and (zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or 
zahl6=$b) and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c 
or zahl6=$c) and (zahl1=$e or zahl2=$e or zahl3=$e or zahl4=$e or 
zahl5=$e or zahl6=$e) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f 
or zahl5=$f or zahl6=$f))

or


((zahl1=$a or zahl2=$a or zahl3=$a or zahl4=$a or zahl5=$a or zahl6=$a) 
and (zahl1=$b or zahl2=$b or zahl3=$b or zahl4=$b or zahl5=$b or 
zahl6=$b) and (zahl1=$c or zahl2=$c or zahl3=$c or zahl4=$c or zahl5=$c 
or zahl6=$c) and (zahl1=$d or zahl2=$d or zahl3=$d or zahl4=$d or 
zahl5=$d or zahl6=$d) and (zahl1=$f or zahl2=$f or zahl3=$f or zahl4=$f 
or zahl5=$f or zahl6=$f)) ;


well.. this query is working. But for sure totaly ineffictive written. I 
need the advice of your professionals to more simply that query.
As next problem i have to search if already 4 of the given 6 numbers are 
machting the 6 numbers per entrie.
But to write a query like i did above.. wount do the trick i guess. Any 
hints? i really need it soon :(

greets,

Yze


В списке pgsql-sql по дате отправления:

Предыдущее
От: ljb
Дата:
Сообщение: Re: libpq-fe: PQgetvalue() ?
Следующее
От: Thomas F.O'Connell
Дата:
Сообщение: Re: help with to_date and to_char