英文:
How can I use SQL to group and count data to get a specific output?
问题
以下是 SQL 查询以获得给定输出的部分:
SELECT cust_name, device, brand
FROM your_table_name
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
选择 计数(cust_name) 作为 用户, 计数(brand) 作为 设备
从 [表名]
按 用户 分组
英文:
something like
select count(cust_name) as users, count(brand) as devices
from [table name]
group by users
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论