[英]Merge of two select queries
I want to merge these two Select queries into single query. 我想将这两个Select查询合并到单个查询中。 How can i do this?
我怎样才能做到这一点?
SELECT link_id, COUNT(*) FROM Loc GROUP BY link_id
SELECT Slink.[xlink:Show],Loc.[xlink:show],
Slink.[xlink:actuate],Loc.[xlink:actuate] ,
href, Sem.SemRoleDescrip
FROM Sem JOIN Loc ON
Sem.SemRoleId = Loc.SemRoleId
JOIN Slink ON Slink.link_id = Loc.link_id
COUNT
statement as a subquery COUNT
语句添加为子查询 (LEFT) JOIN
this subselect with the SLink
table (LEFT) JOIN
使用SLink
表(LEFT) JOIN
此子选择 LinkCount
to the list of selected values. LinkCount
添加到所选值的列表。 SELECT Slink.[xlink:Show]
, Loc.[xlink:show]
, Slink.[xlink:actuate]
, Loc.[xlink:actuate]
, href
, Sem.SemRoleDescrip
, SLinkCount.LinkCount
FROM Sem
JOIN Loc ON Sem.SemRoleId = Loc.SemRoleId
JOIN Slink ON Slink.link_id = Loc.link_id
LEFT JOIN (
SELECT link_id, COUNT(*) AS LinkCount
FROM Loc
GROUP BY
link_id
) SLinkCount ON SLinkCount.link_id = Slink.link_id
You might want to read up on Subqueries in the reference manual 您可能需要阅读参考手册中的“子查询”
12.2.9.8.
12.2.9.8。 Subqueries in the FROM Clause
FROM子句中的子查询
Subqueries are legal in a
SELECT
statement'sFROM
clause.子查询在
SELECT
语句的FROM
子句中是合法的。 The actual syntax is:实际语法是:
SELECT ... FROM (subquery) [AS] name ...
The
[AS]
name clause is mandatory, because every table in aFROM
clause must have a name.[AS]
name子句是强制性的,因为FROM
子句中的每个表都必须有一个名称。 Any columns in the subquery select list must have unique names.子查询选择列表中的任何列都必须具有唯一的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.