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

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())

Related

How to update only the year of the date column in a table - sql oracle [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 3 years ago.
Improve this question
I was looking for the query which can update only the year of the date column to 2019.
yes you can,
if the field of the date for you mydate from table_name, you can do:
Update table_name
set column_name = Add_months(sysdate, -(extract(year from sysdate)-extract(year from mydate))*12)
where <where_condition>;

Write a query that select all events ordered by a particular customer in SQL [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
In SQL how we will write a query that selects all events ordered by a particular customer. Kindly help me there.
Thanks
The table's name is events?...
Select * from events order by custumers asc
if not
select events from Table order by custumers asc

How to get total count of orders placed on spesific date using Raw query [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 8 years ago.
Improve this question
I have ORDER Table in which I am saving Orders date wise.
Now I want total number of orders placed on specific date
How to do that
Pls Help...
Try this:-
SELECT COUNT(*)
FROM TABLE_NAME
WHERE DATE_COL = 'YOUR_DATE'

Insert into a backup table based on date [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 8 years ago.
Improve this question
My table in Oracle 11g has 6 fields. I also have a backup table also with no values. The original table has 2 date values. I need to insert into the backup table from the original table the orders having an order-date 5 months back as of today.
The table has a field names ORDER-DATE and has records entered inside.
insert into backup_table
select * from original_table
where order-data > add_months(sysdate,-5);

Problems with SQL query finding three names with the most records [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 8 years ago.
Improve this question
I have a table and I want to display the 3 names (Ted, Ringo, Paul) that have the most records using an SQL query.
It's a primitive question, but please help me.
my table:
SELECT TOP 3 Name
FROM YourTable
GROUP BY Name
ORDER BY COUNT(*) DESC