联接两个表在mysql输出中显示为null

时间:2018-08-13 06:00:42

标签: mysql sql

我试图在MySQL中联接两个表,但输出显示为null。

供应商

id vname        contactno    email                 address  status
1  raja         715487240  kobi.ram@hotmail.com   badulla    2
2  janarthan    77722222   jaranthan@gmail.com    Hali-ela   1

purchase

id   vendor_id    date         total     pay    due  payment_type

400     2        2018-10-08    10000    8000    2000     2
401     2        2018-10-12    12000    6000    6000     2

sql查询

select
    v.vname, p.id, p.date, p.total, p.pay, p.due, p.payment_type
from purchase p, vendor v
WHERE p.vendor_id = v.id and date BETWEEN 2018-10-01 and 2018-10-31

3 个答案:

答案 0 :(得分:3)

我认为您应该使用单引号进行日期比较,然后对老式的联接说再见,如下所示以新格式更改联接

        <option *ngFor="let prior of priorityOptions" [value]="prior" [selected]="prior == priorityOptions[rowData.PlanPriority -1]">{{prior}}</option>
      </select>
    </td>
    <!-- <p-dropdown  [(ngModel)] ="rowData.Priority" [options]="cities"  placeholder="" optionLabel="name" ></p-dropdown>-->

    <!-- <td *ngIf="statusOptions[rowData.Status-1] == 'TreatmentDefined'; else notTreatmentDefined">
      <select class="form-control" (change)="updateStatusByOrderId(rowData,$event.target.value)">
        <option *ngFor="let status of planStatusAcceptOrReject" [disabled]="status === 'TreatmentDefined'" [value]="status">{{status}}</option>
      </select>
    </td>
    <ng-template #notTreatmentDefined>
      <td>
        {{statusOptions[rowData.Status-1]}}
      </td>
    </ng-template> -->
    <td>
      {{statusOptions[rowData.Status-1]}}
    </td>
    <td *ngIf="statusOptions[rowData.Status-1] == 'Pending' && rowData.PlanNotes.length === 0 ; else elsepart2">
      <i style="color: lightgray;" class="fa fa-plus fa-2x"></i>
    </td>
    <td #elsepart2 *ngIf="statusOptions[rowData.Status-1] == 'Pending' && rowData.PlanNotes.length !== 0 ">
      <i title={{rowData.PlanNotes}} style="color: lightgray;" class="fa fa-edit fa-2x"></i>
    </td>
  </tr>
</ng-template>

提琴:http://sqlfiddle.com/#!9/984801/1

答案 1 :(得分:0)

分别使用join和where子句,您错过了日期值中的报价

    select v.vname,p.id,p.date,p.total,p.pay,p.due,p.payment_type     
    from purchase p inner join vendor v on
    p.vendor_id = v.id  
    where p.date>= '2018-10-01' and  p.date <='2018-10-31'

http://sqlfiddle.com/#!9/4704eb/6

答案 2 :(得分:0)

我认为它的发生是由于日期时间格式

请在查询之前添加日期格式

- name: "Template source files to temp directory"
  file:
    path: '{{ temp_file_path.path }}/{{ item.path }}'
    state: directory
  with_filetree: "{{ nginx_path }}/"
  delegate_to: 127.0.0.1
  when: item.state == 'directory'