Lee Redhead
asked on
How can I count the times something has occured from odd and even number in SQL?
Hello,
I have a very strange problem that I am trying to solve and am stuck.
I currently need to work out how many times an event would have occured depending on the total times it would have been possible. SOund confusing so I will explain.
There is a set interval for an event to happen, so for example every 10 days the colour of an item needs to alternate, so Red,Green,Red,Green,etc.
Now the total time to check this over is say 50 days, so the cycle has happened 5 times.
This means that Red has been shown 3 times and Green has been shown 2 times.
How can I work this out programtically within SQL? So for example the system querys the data and works out that the time of 74 days it would then work out how many times Green has been shown and how many times Red has been shown?
Lee
I have a very strange problem that I am trying to solve and am stuck.
I currently need to work out how many times an event would have occured depending on the total times it would have been possible. SOund confusing so I will explain.
There is a set interval for an event to happen, so for example every 10 days the colour of an item needs to alternate, so Red,Green,Red,Green,etc.
Now the total time to check this over is say 50 days, so the cycle has happened 5 times.
This means that Red has been shown 3 times and Green has been shown 2 times.
How can I work this out programtically within SQL? So for example the system querys the data and works out that the time of 74 days it would then work out how many times Green has been shown and how many times Red has been shown?
Lee
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Prefect, thank you very much.
SELECT CASE ROUND(74/10, 0) % 2 WHEN 1 THEN 'Red'
ELSE 'Green'
END