mysql - Exclude duplicate rows in query result -


i want count number of records in database more 2 tables joined.

for example have table this.

table jobd  +  name     1  |  joba     2  |  jobb  tablea imgeid  +  orderid   +    jobid          1 |  1         |    1       2 |  2         |    1       3 |  3         |    1       4 |  4         |    1    (this order not yet started)  tableb taskid  +  orderid   +    task  +  status       1 |  1         |    1     |  updated       2 |  1         |    1     |  updated       3 |  1         |    1     |  completed       4 |  2         |    2     |  saved       5 |  3         |    3     |  completed 

my problem here when count base on status (@ tableb) query results both updated has same orderid.

this sample query same 1 i'm working.

select t.name     count(case when tb.task = 1 , tb.status <> 'completed' tb.status else null end) inprogress,     count(case when tb.task = 1 , tb.status = 'completed' tb.status else null end) completed tablea ta left join tableb tb     on tb.orderid = ta.orderid left join table t     on t.jobid = ta.jobid group t.jobid; 

my results like

name   +    inprogress     +   completed joba   |    2              |   1 

the inprogress results must 1 because has same orderid. reason why has 2 updated because table historical. don't know how can distinct orderid in tableb results 1.

the main point here can count total orders status in progress, completed , not started per job.

i hope question clear. if have other way, please let me know.

can't use count distinct? here's link, see nearer bottom of page, unique field specify: w3schools.com/sql/sql_func_count.asp

 select t.name count(distinct tb.orderid case when tb.task = 1 , tb.status  'completed' tb.status else null end) inprogress, count(distinct tb.orderid case when tb.task = 1 , tb.status = 'completed' tb.status else null end) completed 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -