Welcome to WebmasterWorld Guest from 188.8.131.52
What I would like to do is order the results by whether the sum(featured_program) field equals 0, or something greater than 0 - i.e., I believe, cast or convert the sum(featured_program) field as a boolean.
How do I do this? Have been trying to use "ORDER BY (CAST(sum(featured_program)) as BOOL) DESC" but keep getting errors.
"SELECT COUNT(col) AS total WHERE something='stuff' ORDER BY total";
The key is using the alias for the ORDER BY...
I would try:
"SELECT SUM(col) AS total WHERE something='stuff' ORDER BY total";
Then refer to the manual if you don't get it. Like I said, I don't remember if this works with SUM() off the top of my head or not.
Let's say I had the following data:
id ¦ name ¦ sum(featured_program)
1 ¦ one ¦ 0
2 ¦ two ¦ 8
3 ¦ three ¦ 4
4 ¦ four ¦ 1
5 ¦ five ¦ 0
Let's say I order by sum(featured_program) DESC then name ASC. That would put #2 first, which is not what I want to do. I want to put #4 first, by treating all rows where sum(featured_program)>0 equally, for sorting purposes. Make sense? Am I misreading your reply?
"SELECT id,name,SUM(featured_program) AS total GROUP BY name HAVING featured_program>0 ORDER BY total";
Completely untested, but very similar to something I use with a COUNT()... Hope it gives you some ideas or a direction to go.
You might have to edit the GROUP BY or cols selected depending on your situation...