1

I have a column which stores data in JSON format. Now I need to find count of specific attribute from all rows using same column.

Column Name: LogDetails
Data Format : {"ORDER_STATUS":"SUCCESS","ORDER_TYPE":"ODSP","ORDER_DATE":"27/03/2021","ORDER_POLLING":"\nCOUNTRY : RUSSIA, PO_ACCEPTED_STATE : Success"}

Here I need to find count where all ORDER_STATUS is SUCCESS.

How can we process it using SQL ?

0

2 Answers 2

1

Below Query worked on POSTGRES:

SELECT COUNT(*)
FROM table
WHERE ORDER_STATUS::json->>'ORDER_STATUS' = 'SUCCESS'
Sign up to request clarification or add additional context in comments.

Comments

0

If you are using SQL Server, you can use JSON_VALUE

SELECT COUNT(*)
FROM YourTable t
WHERE JSON_VALUE(t.LogDetails, '$.ORDER_STATUS') = 'SUCCESS';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.