I would like to know if there is a way to simplify the following SQL statement. This is my table.
| SID | name | l1 | l2 | sch |
| 1 | john | | | sch |
| 2 | mary | l1 | | |
| 3 | zack | l1 | l2 | |
| 4 | paul | l1 | l2 | sch |
Either l1 or l2 is filled, or both can be filled
Not every ‘sch’ has a value
What I do is to calculate a daily summary table, but I do it via PHP, I am wondering if it can be done just using SQL. So eg,
- Total count (This is just count(name))
- Count(sch)
- If !empty (l1) OR !empty (l2) THEN l + 1
So now, based on the above
Total count = 4
count(sch) = 2
count(l1 || l2) = 3
Can it be done in SQL?
1 Answer