mysql - Count the no of id if it is not present in another table based on condition using sql -


i have table consists of repid , date.

table: 1 repid   date 108981  2013-04-09 00:00:00.000 108981  2013-04-09 00:00:00.000 108982  2013-04-10 00:00:00.000 108982  2013-04-11 00:00:00.000 108983  2013-04-11 00:00:00.000 108983  2013-04-11 00:00:00.000 

i have table consists of repid , logtime.

table: 2 repid   logtime 108981  2013-04-09 00:00:00.000 108981  2013-04-09 00:00:00.000 108982  2013-04-11 00:00:00.000 108983  2013-04-11 00:00:00.000 108983  2013-04-11 00:00:00.000 108984      2013-04-10 00:00:00.000 

i want count of repid table 1, when logtime not exist rep table 2.

in case need output as

repid       repcount 108982      1 

as date '2013-04-10 00:00:00.000' not exists in table 2 repid - 108982.

i have used query as

select     t1.repid, count(t1.repid) 'rep count'     table1 t1     not exists     (select t2.repid table2 t2      convert(date, t2.logtime) between '2013-04-08 00:00:00.000' , '2013-04-11 00:00:00.000') group     t1.repid 

but returns nothing. please out of problem....

you can use left outer join here.

select    t1.repid, count(t1.repid)     table1 t1 left outer join   table2 t2 on   t1.repid = t2.repid ,   t1.date = t2.logtime   t2.repid null group   t1.repid 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -