Frage

Got a table like:

art.    type    price
a        b       1
a        c       2

would it be possible with a select to show filtered content as:

art.    type    price
a        b       
a        c       2

so that if the type is "b" don't show price data?

select art, type, price from x 
where type="b" hide price
War es hilfreich?

Lösung

Logic of this sort probably best belongs in the presentation, rather than database, layer of your application. However, it is nevertheless possible using either MySQL's IF() function or its CASE expression—for example:

SELECT art, type, IF(type='b',NULL,price) price FROM x;

See it on sqlfiddle.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top