我不是一个经常使用 SQL 的用户,但最近它已经成为我经常使用并开始喜欢它的东西! 目前,我正在使用 postres 数据库来存储我的数据。 长话短说,我正在寻找在 3 列中仅输出 3 个值的查询。 第一列只是使用不同列显示数据库中不同 ID 的总数(以删除重复项)。
第二列是显示所有不同的 ID,其中值是“true”
然后第三列只是显示“测试 ID”的列,以指示该行代表测试 ID。
但我收到以下错误:
错误:FROM 中的子查询必须有别名
第 2 行:(SELECT count(*) AS "Active_IDs" from (select distin...
我可能遗漏了一些明显的东西,或者没有做正确的事情。
这是我正在使用的查询:
select count(*) AS "Total_Inventory" from (select distinct "Name, "Location", "Interactivity" from idtable) totalinv ,
(SELECT count(*) AS "Active_IDs" from (select distinct "Name", "Location", "Interactivity",
from idtable where "Active" = 'true') totalact), 'Test' AS "ID Type"
from npid_it
select
count(distinct (name, location, interactivity)) as "Total_Inventory",
count(distinct (name, location, interactivity)) filter (where active = True) as "Active_IDs",
'Test' as "ID Type"
from idtable