SQL-Statement

Поиск
Список
Период
Сортировка
Искать

SQL-Statement

От:
Markus Espenhain <espenhain@etes.de>
Дата:
Hello all,

I have the problem that I must create an Querry witch looks like:

--snip--

SELECT * FROM Hauptantrag WHERE (select datenfeldname from datenexport)  > (select datum_von from datenexport) AND  (select datenfeldname from datenexport) < (select datenexport.datum_bis from datenexport) limit 10;

--snap--

The statement (select datenfeldname from datenexport) means an fieldname witch is saved in the relation datenexport. In this relation is only one record saved and contains the fields datenfeldname, datum_von and datum_bis.

Can I do something like this?
Have I an syntax problem?

By executing I become 0 results.

Can someone please educate me...

Thanks a lot

Markus
-- 
Markus Espenhain                         Fon:  +49 (7 11) 48 90 83 - 0
ETES - EDV-Systemhaus GbR                Fax:  +49 (7 11) 48 90 83 - 50
Libanonstrasse 58 A * D-70184 Stuttgart  Web: http://www.etes.de

Re: SQL-Statement

От:
"A.Bhuvaneswaran" <bhuvan@symonds.net>
Дата:
> SELECT * FROM Hauptantrag WHERE (select datenfeldname from datenexport)  
> > (select datum_von from datenexport) AND (select datenfeldname from
> datenexport) < (select datenexport.datum_bis from datenexport) limit 10;

It is not correct. You have not defined the condition between hauptantrag 
& datenexport tables. Forward the table structures for assistance.

regards,
bhuvaneswaran

Re: SQL-Statement

От:
colin roald <zmook@gungeralv.org>
Дата:
Quoth Markus Espenhain :
> SELECT * FROM Hauptantrag WHERE (select datenfeldname from
> datenexport) > (select datum_von from datenexport) AND (select
> datenfeldname from datenexport) < (select datenexport.datum_bis from
> datenexport) limit 10;

If I understand you right, you want to compare some column from 
Hauptantrag to a range of values (datum_bis < 'some column' < datum_von),
but you don't know what the column will be ahead of time.

I believe this requires a dynamic sql statement, such as the plpython
command 'execute':

rv = plpy.execute(
        "SELECT * FROM Hauptantrag WHERE %s > %f AND %s < %f" 
        % (colname, datum_von, datum_bis), 
        10)

If you can, it's probably best to rework the logic of your code to 
avoid having to test unknown columns.  


--
colin | perfection is reached, not when there is no longer anything to add, 
roald | but when there is no longer anything to take away. 
						 (antoine de saint-exupery)
FAQ