Find SQL table entry with a check on created at column [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a SQL database table that has one of the columns as "created_at". The column contains the date and time on which the entry was created.
The format of the column is as follows:
2019-07-14 11:36:15.000
How can I run a query which checks if this entry was created within the past 15 minutes from the current time?

In Standard SQL -- assuming that created_at has a datetime/timestamp type, you would use something like:
where created_at > current_timestamp - interval '15 minute'
That said, the date/time functions are notoriously database-dependent. So the exact syntax might vary in your database.

Solution in SQL Server will be:
SELECT *
FROM YourTable
WHERE created_at >= DATEADD(minute, -15, created_at );

Related

Subtract today's date with date column in SQL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a column in SQL item_expired, this column stores data in the form of dates from other items. What I want to ask, how do I subtract existing date in item_expired column with the current date, which will then be stored in the remaining_time column.
I've tried the command below, but isn't working:
SELECT
item_description, item_expired,
item_date = DATEDIFF(DAY, CURRENT_TIMESTAMP, item_expired)
FROM Customers;
As GMB has mentioned in the comment above, date functions depend on the database type you are using. Assuming you are asking about MySQL the below query will provide you with the remaining time required.
select
(CURRENT_DATE - item_expired) as remaining_time
from customers;
While this will provide you with the remaining time, you will have to write a separate insert to insert the remaining time for the table column.
Query in sql server :
select DATEDIFF(day, CURRENT_TIMESTAMP,item_expired)
will give you the difference in days between the current date and the item_expired date
Provide more information about you problef for more direct answers

How can I find duplicate records in clickhouse [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want to know how I can find duplicate data entries within one table in clickhouse.
I am actually investigating on a merge tree table and actually threw optimize statements at my table but that didn't do the trick. The duplicate entries still persist.
Preferred would be to have a universal strategy without referencing individual column names.
I only want to see the duplicate entries, since I am working on very large tables.
The straight forward way would be to run this query.
SELECT
*,
count() AS cnt
FROM myDB.myTable
GROUP BY *
HAVING cnt > 1
ORDER BY date ASC
If that query gets to big you can run it in pieces.
SELECT
*,
count() AS cnt
FROM myDB.myTable
WHERE (date >= '2020-08-01') AND (date < '2020-09-01')
GROUP BY *
HAVING cnt > 1
ORDER BY date ASC

How to find records 2 years from a created date stored in the individual record [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Need help in writing an MS SQL query to delete all data in a table, 2 years or more from when it was originally added. created_date is stored as datetime field type.
Table: users
user_id
user_name
created_date
Try this
DELETE FROM <your_table> WHERE created_date < DATEADD('yy', -2, getdate())
SELECT *
FROM [database].[dbo].[users] where created_date < DATEADD(year,-2,GETDATE())

SQL Server : find rows that specific column value not change in last 24 hour [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
This is my sample table
I want get last row of BB because money column of BB not changed in last 24 hour ...
What is the right query for this in SQL Server ?
SELECT Early.*
FROM sampleTable Early
JOIN sampleTable Older
ON Early.Name = Older.Name
AND Early.Money = Older.Money
AND DATEDIFF ( day , Older.time, Early.time) >= 1
Take note if only one record, there is nothing to compare and wont appear on the query.
You have to make a "after update" trigger and in the trigger insert the records to temp_table including a update datetime column. This will allow to track each update for each row.
This is MySQL trigger example
MySQL
create trigger ai_table_trigger for each row
begin
insert into temp_table(record_id,update_datetime)values(old.id,now());
end

sql expiry date use Trigger OR Schedule a Job [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I have this table :
Now, i like the way when the date expires. EndTime < GETDATE()
expire field is true.
What method should I use? use a trigger to true or a schedule job that run before run any query in this table?
A simple way to do this is to put a computed column:
ALTER TABLE t1
DROP COLUMN expire
GO
ALTER TABLE t1
ADD expire AS CONVERT(BIT, (CASE WHEN EndTime < GETDATE() THEN 1 ELSE 0 END))
GO