Reputation: 16379
Input Table :
By considering the above table I want to list the start and end date grouped by order id for the given input status "b". Right now I am doing it with many sql queries and merging them together in java. But I would like to write it in single sql query in mysql. Can anyone help me to write this in single sql query.
Output :
Upvotes: 0
Views: 94
Reputation: 263943
I suspect you lack the WHERE
clause in your query.
SELECT orderID,
MIN(createdDate) min_date,
MAX(createdDate) max_date
FROM tableName
WHERE 'b' IN (fromStatus, toStatus)
GROUP BY OrderID
Upvotes: 2
Reputation: 18569
Use this:
SELECT OrderId, MIN(createdDate) as MinDate, MAX(createdDate) as MaxDate
FROM tbl1
WHERE fromStatus = 'b' or inputStatus = 'b'
GROUP BY OrderId
Upvotes: 2