关于统计记录总数的问题表结构:
id
order_id
account
ship_country数据:
id--order_id--account--ship_country
1---00001----CO----JP
2---00002----CO----JP
3---00003----CO----JP
4---00004----CO----GB
5---00005----CO----GB
6---00006----CO----FR
7---00007----CO----IT
8---00007----CO----IT想要实现的统计:
统计ship_country一样的记录数,要group by order_id想要的结果:
ship_country---count()
JP----3
GB----2
FR----1
IT----1请问这样的统计语句该怎么写呢?在此先谢过了

解决方案 »

  1.   

    数据:
    id--order_id--account--ship_country
    1---00001----CO----JP
    2---00002----CO----JP
    3---00003----CO----JP
    4---00004----UK----GB
    5---00005----UK----GB
    6---00006----UK----FR
    7---00007----UK----IT
    8---00007----UK----IT
    想要的结果:
    account---ship_country---count()
    CO----JP----3
    UK----GB----2
    UK----FR----1
    UK----IT----1
    如果再加个account条件,请问能实现吗?如果能,请问怎么实现呢??
      

  2.   


    select account,ship_country,count(*)
    form 数据
    group by account,ship_country
      

  3.   

    ACMAIN_CHM大大:
                  你好!你这个语句应该没考虑到order_id这个字段吧??order_id一样的算一个订单!
      

  4.   

    请问这样可以吗??请问这个语句哪里有问题???我只要找出今天上传的数据。
    select `account`,`ship_country`,count(*)
    from (select `account`,`ship_country` from `1_sale_orders` where date(`upload_date`)=curdate() group by `order_id`) group by `account`,`ship_country`
      

  5.   

    的确没注意到。改为如下试一下。select account,ship_country,count(distinct order_id )
    form 数据
    group by account,ship_country