我有两张桌子。我写了这个查询,但没有显示表格结果 怎么写完美查询显示表结果?
Taccess
id userid groupid accesstype
1 2 1 1
2 4 1 1
Tgroup
grugroupid groupbname userid
1 group-1 1
2 group-2 2
3 group-3 3
4 group-4 4
我需要userid = 1的结果 我想显示所有groupid然后显示accesstype userid = 1
grugroupid groupbname accesstype
1 group-1 1
2 group-2 null
3 group-3 null
4 group-4 null
select grugroupid ,
userid ,groupbname ,
(select AccessType from Access where UserID=2 ) as dd,
from TLab_Info
union
select id userid groupid accesstype
from TLab_Access
答案 0 :(得分:1)
def method2(): Unit = {
val _ = method1()
}
结果:
SELECT g.grugroupid,g.groupbname,a.accesstype
FROM Tgroup g LEFT JOIN
Taccess a on g.grugroupid=a.groupid
WHERE (a.accesstype IS NULL) OR (a.accesstype=1)
GROUP BY g.grugroupid,g.groupbname,a.accesstype
请参阅SQL Fiddle中的结果。
答案 1 :(得分:0)
Raging Bull
已发布的其他变体
SELECT DISTINCT
g.grugroupid,
g.groupbname,
a.accesstype
FROM Tgroup g LEFT JOIN
Taccess a ON g.grugroupid = a.groupid
WHERE COALESCE(a.accesstype,1) = 1
测试在这里SQL Fiddle