Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 我们只需跳过索引中的不同字段,SQL Server不会这样做。只有在索引创建之后,您才需要选择不同的日期。\u@Remus:我确实创建了一个索引,优化器确实使用了它。在我的测试中,有2M条记录时,扫描和聚合速度要快得多。跳过扫描是另一回事,如果索引idx1_Sql Server_Datetime_Distinct - Fatal编程技术网

Sql server 我们只需跳过索引中的不同字段,SQL Server不会这样做。只有在索引创建之后,您才需要选择不同的日期。\u@Remus:我确实创建了一个索引,优化器确实使用了它。在我的测试中,有2M条记录时,扫描和聚合速度要快得多。跳过扫描是另一回事,如果索引idx1

Sql server 我们只需跳过索引中的不同字段,SQL Server不会这样做。只有在索引创建之后,您才需要选择不同的日期。\u@Remus:我确实创建了一个索引,优化器确实使用了它。在我的测试中,有2M条记录时,扫描和聚合速度要快得多。跳过扫描是另一回事,如果索引idx1,sql-server,datetime,distinct,Sql Server,Datetime,Distinct,我们只需跳过索引中的不同字段,SQL Server不会这样做。只有在索引创建之后,您才需要选择不同的日期。\u@Remus:我确实创建了一个索引,优化器确实使用了它。在我的测试中,有2M条记录时,扫描和聚合速度要快得多。跳过扫描是另一回事,如果索引idx1在(ColA,ColB)上,并且ColB上的谓词“跳过扫描”将使用idx1,尽管ColA没有谓词。虽然SQL Server中没有跳过扫描,但为True。有关跳过扫描的Microsoft Connect项目:延迟的主要原因是扫描和排序以生成不同的


我们只需跳过索引中的不同字段,
SQL Server
不会这样做。只有在索引创建之后,您才需要选择不同的日期。\u
@Remus
:我确实创建了一个索引,优化器确实使用了它。在我的测试中,有2M条记录时,扫描和聚合速度要快得多。跳过扫描是另一回事,如果索引idx1在(ColA,ColB)上,并且ColB上的谓词“跳过扫描”将使用idx1,尽管ColA没有谓词。虽然SQL Server中没有跳过扫描,但为True。有关跳过扫描的Microsoft Connect项目:延迟的主要原因是扫描和排序以生成不同的。除非标量操作中发生了非常复杂的事情,否则数据库中的延迟总是与数据访问有关,而不是与标量操作有关。这是延迟的主要原因,因为它会强制进行完整的表扫描-对不起,应该是Clear构建一个日期表,然后半连接到原始数据表是一个很好的解决方案。IMHO只有在您必须频繁执行此操作(任意猜测:比如每天数百次)时,使用索引或索引视图的持久化列的额外开销才有意义。我总是倾向于首先尝试提出一个更好的查询,而不是给数据库结构增加更多的复杂性/开销。不确定效率,但这绝对是最好的方法。
CAST(FLOOR(CAST(@date as FLOAT)) as DateTime);
WITH    rows AS (
        SELECT  CAST(CAST(CAST(MIN(date) AS FLOAT) AS INTEGER) AS DATETIME) AS mindate, MAX(date) AS maxdate
        FROM    mytable
        UNION ALL
        SELECT  mindate + 1, maxdate
        FROM    rows
        WHERE   mindate < maxdate
        )
SELECT  mindate
FROM    rows
WHERE   EXISTS
        (
        SELECT  NULL
        FROM    mytable
        WHERE   date >= mindate
                AND date < mindate + 1
        )
OPTION  (MAXRECURSION 0)
Unless otherwise specified, computed columns are virtual columns that are not physically stored in the table. Their values are recalculated every time they are referenced in a query. The Database Engine uses the PERSISTED keyword in the CREATE TABLE and ALTER TABLE statements to physically store computed columns in the table. Their values are updated when any columns that are part of their calculation change. By marking a computed column as PERSISTED, you can create an index on a computed column that is deterministic but not precise.
alter table foo add date_only as convert(char(8), [datetimecolumn], 112) persisted;
create index idx_foo_date_only on foo(date_only);
create view v_foo_with_date_only
with schemabinding as 
select id
    , convert(char(8), [datetimecolumn], 112) as date_only
from dbo.foo;   
create unique clustered index idx_v_foo on v_foo_with_date_only(date_only, id);
create view v_foo_with_date_only
with schemabinding as 
select
    convert(char(8), [d], 112) as date_only
    , count_big(*) as [dummy]
from dbo.foo
group by convert(char(8), [d], 112)

create unique clustered index idx_v_foo on v_foo_with_date_only(date_only)
SELECT DISTINCT DATEADD(day, 0, DATEDIFF(day, 0, your_date_column))
FROM your_table
SELECT
DISTINCT DATE_FORMAT(your_date_column,'%Y-%m-%d') AS date
FROM ...
SELECT distinct(CONVERT(varchar(10), {your date column}, 111)) 
FROM {your table name}