[SQL] queries the records used by a field in the database for a certain period of time.

Source: Internet
Author: User
Tags how to use sql

[SQL] queries the records used by a field in the database for a certain period of time.

Sometimes we often need to use some tables or execute a stored procedure. Sort out the SQL queries executed by the database in a certain period of time. You can also query the storage of some fields in the database. Very good, very powerful, hope to help you ~

Select top 1000 -- Creation Time QS. creation_time, -- query statement SUBSTRING (ST. text, (QS. statement_start_offset/2) + 1, (case qs. statement_end_offset WHEN-1 then datalength (st. text) else qs. statement_end_offset END-QS. statement_start_offset)/2) + 1) AS statement_text, -- execute the text ST. text, -- execution plan QS. total_worker_time, QS. last_worker_time, QS. max_worker_time, QS. min_worker_time FROM sys. dm_exec_query_stats QS -- Keyword cross apply sys. dm_exec_ SQL _text (QS. SQL _handle) ST WHERE QS. creation_time BETWEEN '2017-12-2013: 00: 00' AND '2017-12-03 11:00:00 'and st. text LIKE '% BK_TSESTATU %' order by qs. creation_time


In the following code, BK_TSESTATU is the field for fuzzy search.

ST.text LIKE '%BK_TSESTATU%' 



SQLserver2005

Select CONVERT (varchar (12), Date Field, 112), sum (accumulate field) from table name where Date Field between'2017-01-01 'and '2017-01-31' group by CONVERT (varchar (12), Date Field, 2013)

I used the date range from January 1-1 to 31. Change it by yourself.

How to use SQL statements to query duplicate rows of a specific field in the database

I usually use this:
Assume that the repeated field names are suspected to be SeriNo,

Select * from [tablename]
Group by SeriNo
Having count (SeriNo) <> 1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.