如何按计数订购我的加入结果?

时间:2017-09-07 13:13:25

标签: mysql

我有2个表shipmentssupport_tickets,2个表中的公共元素是tracking_id。我想根据support_tickets表中的条件来计算提供者名称。我试过这个:

MySQL查询:

SELECT provider,count(provider) as pen_tick_iss 
from shipments 
inner join support_tickets on shipments.tracking_id=support_tickets.tracking_id 
where support_tickets.issue_status = 'Pending'  
AND support_tickets.ticket_flag = '1' 
AND support_tickets.multi_loc_pickup = '0' 
AND support_tickets.status = 'Active'  
group BY provider ORDER BY count(provider) DESC

shipments

id  tracking_id provider    created_date
1   1231232332  fedex   01-09-2017
2   3435435345  fedex   02-09-2017
3   56564564    aramex  03-09-2017
4   535456456   fedex   04-09-2017
5   4565465 delhivery   05-09-2017
6   45656456    fedex   06-09-2017
7   3453453534  fedex   07-09-2017
8   6856865856  delhivery   08-09-2017
9   99923423432 fedex   09-09-2017
10  99923434    delhivery   10-09-2017
11  343343423   aramex  11-09-2017
12  93458345    aramex  12-09-2017
13  435345345   delhivery   13-09-2017
14  3454462136  fedex   14-09-2017
15  989798723   delhivery   15-09-2017

support_tickets

id  tracking_id issue_status    status  ticket_flag created_date
1   1231232332  pending Active  1   01-09-2017
2   3435435345  pending Active  1   11-09-2017
3   56564564    pending Active  1   11-09-2017
4   535456456   fixed   Active      15-09-2017
5   4565465 pending Deleted 1   15-09-2017
6   45656456    pending Active  1   15-09-2017
7   3453453534  fixed   Active      16-09-2017
8   6856865856  fixed   Active      17-09-2017
9   99923423432 pending Active  0   18-09-2017
10  99923434    pending Active  0   19-09-2017
11  343343423   pending Deleted 1   20-09-2017
12  93458345    fixed   Active      21-09-2017
13  435345345   pending Active  1   22-09-2017
14  3454462136  pending Active  1   23-09-2017
15  989798723   fixed   Active      24-09-2017

0 个答案:

没有答案