统计记录总数的问题

zhuhao 2013-09-20 11:46:47
关于统计记录总数的问题

表结构:
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

请问这样的统计语句该怎么写呢?在此先谢过了


...全文
284 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2013-09-22
  • 打赏
  • 举报
回复
引用 3 楼 zhuhao 的回复:
ACMAIN_CHM大大: 你好! 你这个语句应该没考虑到order_id这个字段吧??order_id一样的算一个订单!
的确没注意到。 改为如下试一下。 select account,ship_country,count(distinct order_id ) form 数据 group by account,ship_country
zhuhao 2013-09-20
  • 打赏
  • 举报
回复
数据: 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条件,请问能实现吗?如果能,请问怎么实现呢??
zhuhao 2013-09-20
  • 打赏
  • 举报
回复
请问这样可以吗??请问这个语句哪里有问题???我只要找出今天上传的数据。 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`
zhuhao 2013-09-20
  • 打赏
  • 举报
回复
ACMAIN_CHM大大: 你好! 你这个语句应该没考虑到order_id这个字段吧??order_id一样的算一个订单!
ACMAIN_CHM 2013-09-20
  • 打赏
  • 举报
回复
引用 1 楼 zhuhao 的回复:
数据: 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条件,请问能实现吗?如果能,请问怎么实现呢??
select account,ship_country,count(*) form 数据 group by account,ship_country

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧