Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在查询中重命名值_Mysql_Database_Javafx_Javafx 8_Pie Chart - Fatal编程技术网

Mysql 在查询中重命名值

Mysql 在查询中重命名值,mysql,database,javafx,javafx-8,pie-chart,Mysql,Database,Javafx,Javafx 8,Pie Chart,我在mySQL数据库中重命名列中的特定值时遇到问题。起初我以为我可以用“AS”来重命名,但实际上我正在尝试重命名列中的一个值。我的专栏名为FoundLost。在此列中,我存储值“0”和“1”已找到“0”,但“1”已丢失 我需要重命名此值的原因是因为我使用此数据库中的数据来创建pieChart。通过函数.getName,它给出了名称“0”和“1” 我希望有人能帮我 带有查询的类的代码如下所示: public static ObservableList getPChartFoundLost() {

我在mySQL数据库中重命名列中的特定值时遇到问题。起初我以为我可以用“AS”来重命名,但实际上我正在尝试重命名列中的一个值。我的专栏名为FoundLost。在此列中,我存储值“0”和“1”已找到“0”,但“1”已丢失

我需要重命名此值的原因是因为我使用此数据库中的数据来创建pieChart。通过函数.getName,它给出了名称“0”和“1”

我希望有人能帮我

带有查询的类的代码如下所示:

public static ObservableList getPChartFoundLost() {
    String query = "SELECT FoundLost, concat(round(count(FoundLost) *100 / (SELECT count(FoundLost) FROM Luggage))) AS percent FROM Luggage GROUP BY FoundLost";

    ObservableList FoundLost = FXCollections.observableArrayList();

    Connection connection = DatabaseUtils.connect();

    if (connection != null) {
        try {
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(query);

            while (resultSet.next()) {

                FoundLost.add(new PieChart.Data(resultSet.getString("FoundLost"), resultSet.getInt("percent")));
            }

            resultSet.close();
            statement.close();
        } catch (SQLException sqle) {
            System.out.println(sqle.getMessage());
        }
        DatabaseUtils.disconnect(connection);
    }

    return FoundLost;
}
控制器:

    public void clickPChartFoundLost(ActionEvent event) {

    //PieChart
    ObservableList FoundLost = StatisticsUtils.getPChartFoundLost();

    pieChart.setVisible(true);
    pieChart.setData(FoundLost);
    pieChart.setTitle("Found and Lost luggage");

    for (final PieChart.Data data : pieChart.getData()) {
        data.getNode().addEventHandler(MouseEvent.ANY,
                new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent e) {

                //Label vullen met data van Observable list uit Database
                pieChartValueLable.setText(String.valueOf(data.getName()) + ": "
                        + String.valueOf(data.getPieValue()) + "%");
            }
        });
    }
}
public void单击PChartFoundLost(操作事件){
//皮查特
ObservableList FoundLost=StatisticsUtils.getPChartFoundLost();
pieChart.setVisible(true);
pieChart.setData(FoundLost);
pieChart.setTitle(“失物招领行李”);
对于(最终PieChart.Data数据:PieChart.getData()){
data.getNode().addEventHandler(MouseEvent.ANY,
新的EventHandler(){
@凌驾
公共无效句柄(MouseEvent e){
//标签VULEN met数据van可观察列表uit数据库
pieChartValueLable.setText(String.valueOf(data.getName())+“:”
+String.valueOf(data.getPieValue())+“%”;
}
});
}
}

谢谢

在查询中,尝试将此列作为第一列,而不仅仅是
FoundLost
。它将
0
1
值转换为图表中有意义的字符串。查询的其余部分可以保持不变

IF(FoundLost = 0,'Found','Lost') AS FoundLost