Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL查询问题SQLite_Sql_Sqlite - Fatal编程技术网

SQL查询问题SQLite

SQL查询问题SQLite,sql,sqlite,Sql,Sqlite,4柱 | day of year | year | user A | user B | 1 1 john ron 2 1 ron john 1 2 john kyle 我需要计算用户在UserA列或UserB列中出现的次数 group by UserA COLL不成功我需要计算john在UserA和UserB cols中总共出现了多少次 预期

4柱

| day of year | year | user A | user B |

      1          1      john      ron
      2          1       ron      john
      1          2       john     kyle
我需要计算用户在UserA列或UserB列中出现的次数

group by UserA COLL不成功我需要计算john在UserA和UserB cols中总共出现了多少次

预期产量

john 3
ron 2
kyle 1

您似乎希望
全部联合

select user, count(*) counts from
(
    select [user A] as user from table t
    union all
    select [user B] as user from table t
)a
group by user

您似乎希望
全部联合

select user, count(*) counts from
(
    select [user A] as user from table t
    union all
    select [user B] as user from table t
)a
group by user

您可以编写如下查询:-

select user, sum(cnt) total
from 
(select userA as user, count(*) cnt from table group by userA
UNION ALL
select userB as user, count(*) cnt from table group by userB
) a11
group by user

您可以编写如下查询:-

select user, sum(cnt) total
from 
(select userA as user, count(*) cnt from table group by userA
UNION ALL
select userB as user, count(*) cnt from table group by userB
) a11
group by user