比较sql中的两个组数据

时间:2017-10-31 02:56:55

标签: mysql sql

我有比较两个表的问题: 甲

id x
1  2
1  5
1  4
1  6 

id x
1  2
1  5
1  4
1  6 

我想知道表A和B中的数据是否与id = 1相同。

1 个答案:

答案 0 :(得分:1)

这将列出id=1ab中没有SELECT a.* FROM a LEFT JOIN b ON a.id = b.id AND a.x = b.x AND a.id = 1 WHERE b.x IS NULL; 的所有b.x行:

id=1

在左连接中,当{a.id,ax}对没有相应的{b.id,bx}对时,b将为空。< / p>

要列出aSELECT b.* FROM b LEFT JOIN a ON b.id = a.id AND b.x = z.x AND b.id = 1 WHERE z.x IS NULL; 但不在a中的b行,只需转动查询:

b

将两者合并以查找哪些行位于a但不是id=1,并且位于SELECT a.*, b.* FROM a LEFT JOIN b ON a.id = b.id AND a.x = b.x AND a.id = 1 WHERE b.x IS NULL UNION SELECT a.*, b.* FROM b LEFT JOIN a ON b.id = a.id AND b.x = z.x AND b.id = 1 WHERE z.x IS NULL; 但不是$cordovaGeolocation.getCurrentPosition(options).then( function(position){ $scope.startingLat = position.coords.latitude; $scope.startingLng = position.coords.longitude; services.projectStreets().then(function(result){ $scope.projects = result.data; for (var i = 0; i < $scope.projects.length; i++) { var endingLat = $scope.projects[i].position.lat; var endingLng = $scope.projects[i].position.lng; // this works to add key and value-> $scope.projects[i].distanceNew = "hi" + i; services.googleMapsDistance($scope.startingLat, $scope.startingLng, endingLat, endingLng) .then(function(distances){ $scope.distanceAway = distances.data; $scope.projects[i]['distanceFrom'] = $scope.distanceAway.rows[0].elements[0].distance.text; } ); } }); } ) 。如果查询未返回任何行,则<ion-item ng-repeat="project in projects" ng-click="goDeetz({{project.Nid}})"> <div class="row"> <div class="col-9"> {{project.title}}<br> <a>{{project.project_dates}}</a> </div> <div class="col-3"> {{distanceAway.rows[0].elements[0].distance.text}} </div> </div> </ion-item> 的两个表中的值都相同。如果它确实返回行,则它们是不同的行。

try:
    br.form.find_control( 'Entries[registration_ip]').readonly = False
    print "Form found ",
    break
except mechanize.ControlNotFoundError:
    print "ControlNotFoundError"
    br.open(url)
    br.select_form(nr = 0)
    br.form.find_control( 'Entries[registration_ip]').readonly = False