sql - Mysql group by that counts have different logic -


i have table 3 fields:.

field1 - field2 - field3 

field1 id;
field2 date;
field3 has 2 possible values ("ac" , "re").

i need know if possible have query group by give me results shown @ end:

select field2        , count(total per date)        , count(where field3 = "re")    mytable  group 1; 

if table is:

field1 - field2 - field3 =========================  item1 - date1  - "ac"  item2 - date1  - "re"  item3 - date1  - "re"  item4 - date2  - "re"  item5 - date2  - "ac"  item6 - date3  - "ac" 

the result like:

 - date1 - 3 - 2  - date2 - 2 - 1  - date3 - 1 - 0 

select field2, count(*), sum(case when field3='re' 1 else 0 end) re_count table1 group field2 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -