On Vi, 2002-11-01 at 18:23, marian wrote:
> Pe o baza de data mysql trebuie sa fac un search dupa mai multe criterii.
mai jos este pentru postgresql
Pentru 4 conditii avem asa
CREATE TABLE cond (
titlu VARCHAR(16),
c1 INTEGER,
c2 INTEGER,
c3 INTEGER,
c4 INTEGER
);
INSERT INTO cond VALUES ( 'nimic', 0, 0, 0, 0 );
INSERT INTO cond VALUES ( 'jumatate', 1, 0, 3, 0 );
INSERT INTO cond VALUES ( 'tot', 1, 2, 3, 4 );
INSERT INTO cond VALUES ( 'nimic2', 0, 0, 0, 0 );
INSERT INTO cond VALUES ( 'trei sferturi', 0, 2, 3, 4 );
INSERT INTO cond VALUES ( 'tot2', 1, 2, 3, 4 );
INSERT INTO cond VALUES ( 'un sfert', 0, 2, 0, 0 );
INSERT INTO cond VALUES ( 'nimic3', 0, 0, 0, 0 );
SELECT-ul dorit de tine este
SELECT *,
( CASE WHEN c1=1 THEN 1 ELSE 0 END
+ CASE WHEN c2=2 THEN 1 ELSE 0 END
+ CASE WHEN c3=3 THEN 1 ELSE 0 END
+ CASE WHEN c4=4 THEN 1 ELSE 0 END ) * 100 / 4
AS procent_potrivire
FROM cond
WHERE c1=1
OR c2=2
OR c3=3
OR c4=4
ORDER BY procent_potrivire DESC;
titlu | c1 | c2 | c3 | c4 | procent_potrivire
---------------+----+----+----+----+-------------------
tot | 1 | 2 | 3 | 4 | 100
tot2 | 1 | 2 | 3 | 4 | 100
trei sferturi | 0 | 2 | 3 | 4 | 75
jumatate | 1 | 0 | 3 | 0 | 50
un sfert | 0 | 2 | 0 | 0 | 25
(5 rows)
liniile cu CASE si OR le generezi dinamic probabil, functie de cate
conditii sunt folosite.
--
SoluĊ£ii informatice bazate pe Linux / Linux-based IT solutions
www.galuna.ro
---
Pentru dezabonare, trimiteti mail la
[EMAIL PROTECTED] cu subiectul 'unsubscribe rlug'.
REGULI, arhive si alte informatii: http://www.lug.ro/mlist/