用CASE WHEN选择,然后用THEN代替String

时间:2018-06-07 06:53:46

标签: postgresql

我的查询是:

tag`template literal`

是否可以将SELECT id, CASE WHEN EXISTS( SELECT data_od FROM bp_stan_produkt WHERE id_produkt = bp_produkt.id AND data_do IS NULL AND id_stan_produkt = 313 ) THEN 'TAK' ELSE 'NIE' END AS "313" FROM bp_produkt WHERE id IN(21048528) 添加到列data_od而不是313,还是必须创建函数,make TAKSELECT data_od into some_variable

1 个答案:

答案 0 :(得分:1)

是的,有可能:

import javafx.geometry.Insets;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;

public class ExpandableNode extends BorderPane {
    private static final int PREVIEW_SIZE = 140;
    TextFlow preview;
    Hyperlink expand;

    /**
     * this node demonstrates something expandable using a TextFlow
     */
    public ExpandableNode() {
        setTop(new Label("this is the title area"));
        this.setPadding(Insets.EMPTY);
        preview = new TextFlow();
        expand = new Hyperlink("more");
        setCenter(preview);
        Pane hSpace = new Pane();
        hSpace.setPrefWidth(25);
        // shame on me this shall go to css, but its a sample...
        hSpace.setStyle("-fx-background-color: transparent;");
        setLeft(hSpace);
        setBottom(new Label("this is the status area"));
    }

    public void setContent(final String item) {
        String shortItem = item.substring(0, PREVIEW_SIZE+3)+"...";
        process(preview, shortItem);
        preview.getChildren().add(expand);

        expand.setOnAction(ae -> {
            process(preview, item);
        });
    }

    public void process(TextFlow preview, String text) {
        preview.getChildren().clear();
        // this is an example so this code does not make sense here...
        String[] lines = text.split("\n");
        for (int i = 0; i < lines.length; i++) {
            Text line = new Text(lines[i]+"\n");
            preview.getChildren().add(line);
        }
      // trigger some event?
    }
}

编辑:

select id, 
  case when exists (select data_od from bp_stan_produkt 
                  where id_produkt = bp_produkt.id and data_do is null 
                   and id_stan_produkt = 313) 
   then  (select to_char(data_od, 'YYYY-MM-DD')
                   from bp_stan_produkt 
                   where id_produkt = bp.id 
                     and data_do is null
                     and id_stan_produkt = 313)
  else 'NIE'
  end as "313"
from bp_produkt 
where id in(21048528);