sql - mysql count distinct positive values but count all -1 values in table and give total? -


i have table called ptb_profile_views looks this:

id | profile_id | viewed_profile_id 1        2              6 2        2              6 3        3              6 4       -1              6 5       -1              6 

i have been trying count positive values in 'profile_id' once distinct values , count -1 values many times appear following query:

function check_profile_views3() { global $connection; global $_session; $query = " select id,profile_id,viewed_profile_id count ptb_profile_views  profile_id > 0 group profile_id union /*shows -1 profile id's*/ select id,profile_id,viewed_profile_id  ptb_profile_views  profile_id <= 0"; $check_profile_views_set3 = mysql_query($query, $connection); confirm_query($check_profile_views_set3); return $check_profile_views_set3;                } 

so end result

2, 3, -1, -1 

but instead of echoing out actual values them selves want query count of values.

so...

2, 3, -1, -1 = total of 4 

i trying call query don't know if work:

$check_profile_views_set3 = check_profile_views3(); while ($views3 = mysql_fetch_array($check_profile_views_set3)) {   echo "".$views3['profile_id'].""; ?> 

can please show me how can this? thanks

select + b totalcount         (           select count(distinct profile_id)             ptb_profile_views            profile_id > 0         ) x,         (           select count(profile_id) b             ptb_profile_views            profile_id < 0         ) y 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -