[英]SQL Query to get data from each column
I have multiple columns in a table 我在一个表中有多个列
One column may contain the name of the state (US), another column contains the speciality 一列可能包含州名(美国),另一列可能包含专业名称
Here is some sample data (there could be more than one C# in NY and may also exist in other states) 这是一些示例数据(在纽约可能有多个C#,在其他州也可能存在)
C# NY
C# NJ
C# WA
C# CA
C# NY
C# NY
Java NY
Java NJ
Java IL
Basically I want to get an output that has 基本上我想得到一个输出
C# 100 (sum of all states that have C#)
Java 85 (sum of all states that have Java)
and I would like to get 我想得到
State Total Speciality
NY 150 C#
NY 100 C++
I am using SQLite3 as my DB 我正在使用SQLite3作为数据库
SqlLite should have GROUP BY and COUNT. SqlLite应该具有GROUP BY和COUNT。 You may try:
您可以尝试:
SELECT Speciality, COUNT(State) AS Total
FROM YourTable
GROUP BY Speciality
and 和
SELECT State, Speciality, COUNT(*) AS Total
FROM YourTable
GROUP BY State, Speciality
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.