联接表时计算缺少条件

时间:2020-02-15 05:57:35

标签: sql-server

我确定这并不难,但是我无法弄清楚单词来在线搜索答案。情况如下:

我有两个表,交易和交易明细。我需要修改在事务处理中连接表时没有特定值的记录。

Transaction           Transaction Detail

Tran ID tran_type     Tran ID   Tranhead_id
1       45              1           145
2       3               1           148
3       45              2           230
                        2           467
                        3           220
                        3           310

我需要按tran_id联接这些表,然后选择tran_type 45的交易记录,该记录在tranhead_id = 145的交易明细中没有匹配记录。在这种情况下,tran_id 3是唯一选择的记录。

1 个答案:

答案 0 :(得分:1)

我在这里使用一个existing子句:

public static List<String> findPathToNode(Node rootNode, Point toFind) {
    // @ToDo Implement this routine
    List<String> nodeList = new ArrayList<>();

    return getAllNodesForPoint(rootNode, toFind, nodeList);   }

  //Recursive function to loop through all nodes of tree and return empty LinkedList   // if point not found or NOT Empty with the path to the point, if point is found

  static List<String> getAllNodesForPoint(Node n, Point p, List<String> list) {
    list.add(n.getId());
    for (Node temp : n.getChildren()) {
      if (temp.getChildren().size() > 0) {
        if (isContained(temp, p)) {
          list.add(temp.getId());
          return list;
        } else {
          getAllNodesForPoint(temp, p, list);
        }
      } else {
        list = new LinkedList<>();
        list.add(n.getId());
      }
    }
    list = new ArrayList<>();
    return list;   }

  static boolean isContained(Node e, Point p){
    Point topLeft = new Point(e.getLeft(), e.getTop());
    Point topRight = new Point(e.getLeft()+e.getWidth(), e.getTop());
    Point bottomLeft = new Point(e.getLeft(), e.getTop()+e.getHeight());
    Point bottomRight = new Point(e.getLeft()+e.getWidth(), e.getTop()+e.getHeight());
    if(topLeft.getX()<p.getX()
            &&p.getX()<topRight.getX()
            &&topLeft.getY()<p.getY()
            &&bottomLeft.getY()>p.getY()){
      return true;
    }
    else{
      return false;
    }   }