fix bugs in sql syntax when event name was assigned, fix bug to give right total entry count