SELECT id
FROM table1 
WHERE NOT (id = 0)
SELECT id
FROM table1 
WHERE id <> 0
Run Code Online (Sandbox Code Playgroud)
在上面的2个查询中,哪个需要考虑Performance和Coding Standards?
我有一个查询来选择办公室的特定白天时间。
select 
    a.sat_date, 
    b.officeid 
from  
    OfficeHours a 
where 
    sat_date = '9:30 AM'
    and officeik in (select OfficeIK from office where officeid = 50000) b
Run Code Online (Sandbox Code Playgroud)
我需要officeid在主查询中选择子查询列。上面的查询抛出一个syntax error.
谢谢您的帮助。
我们需要建立一个script这将insert只有新created offices和districts成Data table.我们需要检查两者Office和District tables新的Records,如果数据存在,我们需要insert它们.
我们试过以下语法,
IF EXISTS (
    SELECT 1
    FROM [dbo].[office] o
    LEFT OUTER JOIN [dbo].[Datatable] a ON (o.OfficeID = a.OfficeID)
    WHERE a.OfficeID IS NULL
)
OR (
IF EXISTS (
    SELECT 1
    FROM [dbo].[District] o
    LEFT OUTER JOIN [dbo].[Datatable] a ON (o.DistrictID = DistrictID)
    WHERE a.DistrictID IS NULL
)
)
BEGIN
   -- //CODE
END
Run Code Online (Sandbox Code Playgroud)
但SSMS给出syntax error了这一点.如何实现上述场景?
我有一个表,可以按小时计算一周的数据.
这是表结构(一天):
dayId   HourId  amount  category
--------------------------------
1       9       1       a
1       9       1       b
1       9       1       c
1       9       1       d
1      10       1       a
1      10       1       b
1      10       1       c
1      10       1       d
1      11       1       a
1      11       1       b
1      11       0       c
1      11       1       d
1      12       0       a
1      12       2       b
1      12       2       c
1      12       2       d
Run Code Online (Sandbox Code Playgroud)
我使用pivot来查看日常金额分布如下:
select 
    dayid,
    [9],
    [10],
    [11],
    [12]
from
    (select …Run Code Online (Sandbox Code Playgroud)