mysql - SQL WHERE abc = n returns wrong data -


so i'm trying find number of rows according following command:

select count( distinct  `increment_id` )   `orders`   `created_at`  '%2013-07%' ,  `store_id` =1 ,  `status` not  '%canceled%' 

this returns number, x.

select count( distinct  `increment_id` )   `orders`   `created_at`  '%2013-07%' ,  `status` not  '%canceled%' 

this returns number x, wrong. in case 1, number should less in case 2, because i'm filtering more rows.

type of store_id tinyint(4).

are queries wrong? how make work want work?

ps: have checked manually, , number must low. there's nothing skewed data. not records have store_id=1.

just because not rows have same store_id not mean these results should different. if have, example, increment_id has 3 records store_id=1 , store_id=14 , store_id=99 appear in of queries.

try query see examples...

select   `increment_id`,   sum(case when `store_id` = 1 1 else 0 end)  `count_of_store_id_1`,   sum(case when `store_id` = 1 0 else 1 end)  `count_of_store_id_not_1`   `orders`        `created_at`     '%2013-07%'   , `status`     not '%canceled%' group   `increment_id` 

i suspect see every increment_id has at least 1 record store_id = 1


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -