简体   繁体   中英

Query returned values in SQL

I would like to write an SQL query which uses results from previous one.

For example - I have a table Orders with fields: order_id, date and value. I need to get all dates from column date where value is larger than 5:

SELECT date 
FROM Orders 
WHERE value > 5;

Then I need to return all values for dates, which are +2 days from the returned ones. Is it possible to write short query without using LOOP statement?

Here is an example table:

在此处输入图片说明

I am expecting to get the result:

在此处输入图片说明

his will give you what you need.

select date, value  
from Orders where date in
(
  SELECT date + INTERVAL 5 DAY as date
  FROM Orders 
  WHERE value > 100;
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM