你可以使用SQL来分组和计数数据以获得特定的输出。

huangapple go评论93阅读模式
英文:

How can I use SQL to group and count data to get a specific output?

问题

以下是 SQL 查询以获得给定输出的部分:

  1. SELECT cust_name, device, brand
  2. FROM your_table_name
  3. GROUP BY cust_name, device, brand;

请将 "your_table_name" 替换为您的实际表格名称。希望这可以帮助您获得所需的结果。

英文:

query in sql to get the given output?

cust_name device brand
'a' 'settopbox' 'airtel'
'a' 'settopbox' 'dish'
'a' 'settopbox' 'reliance'
'b' 'settopbox' 'airtel'
'd' 'settopbox' 'airtel'
'd' 'settopbox' 'dish'
'd' 'settopbox' 'reliance'
'd' 'settopbox' 'hathway'

Output:

users devices
3 3
1 1
4 4

I am trying in group by but not able to solve completely.

答案1

得分: 1

  1. 选择 计数(cust_name) 作为 用户, 计数(brand) 作为 设备
  2. [表名]
  3. 用户 分组
英文:

something like

  1. select count(cust_name) as users, count(brand) as devices
  2. from [table name]
  3. group by users

huangapple
  • 本文由 发表于 2023年5月22日 04:02:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301708.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定