SELECT
(SELECT COUNT(*) FROM VotesOnPosts WHERE VoteTypeName = 'UpMod' AND UserId = @UserID AND PostTypeId = 2) AS TotalUpVotes,
(SELECT COUNT(*) FROM Answers WHERE UserId = @UserID) AS TotalAnswers
The first one can be seen as a horizontal diminishing opposed to the where-clause which can be seen as a vertical diminishing. On the other hand, a join can augment the set horizontally where a union can augment the set vertically.
augmentation diminishing
horizontal join/select select
vertical union where/inner-join
第二个是映射。一个映射,更多的是一个转换器。在 SQL 中,它接受一些字段并返回零个或多个字段。在 select 中,可以使用一些聚合函数,如 sum、 avg 等。或者将所有列值转换为字符串。在 C # linq 中,我们说 select 接受 T 类型的对象并返回 U 类型的对象。
我认为困惑来自于这样一个事实: 你可以做: select 'howdy' from <table_name>。这个特性就是映射,转换器部分的选择。您不是在打印什么东西,而是在转换!在你的例子中:
SELECT "
WHERE 1 = 1
you are converting nothing/null into "Hello world" and you narrow the set of nothing / no table into one row, which, imho make no sense at all.