Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql query to show count of distinct result
    primarykey
    data
    text
    <p>i have three tables , i want to combine the output of three result and show the result here is my table structure and query</p> <p>table_campaign - ID is auto increment </p> <pre><code>id banner views_left packages 1 A1 555 5 2 A1 527 5 3 B1 580 98 4 C1 293 69 </code></pre> <p>table_packages-Id is auto increment </p> <pre><code>id name special 1 India IND 2 Aus Australia 3 Pak Pakistan </code></pre> <p>tablepage (uri &amp; banner in table_campaign are same)</p> <pre><code> id uri views 1 A1 54 2 B1 94 3 C1 38 </code></pre> <p>i want to check the sum of all banner of similar type in table_campaign and will check with tablepage and if the total views in table_campaign is less than tablepage views then it will display the result.</p> <p>i have tried three independent queries. can you please guide how to write so that if views in tablepage is less than combined view of views_left column of table_campaign it will show the result or it will not show any result. i want to dispaly random result out of several which satisfies this criteria</p> <pre><code>$res23 = sql_query("SELECT sum(views_left) as num from table_campaign where banner!='{$client['uri']}' " ); $row23 = sql_fetch_array($res23); $stats['views_left'] = $row23['num']; $res = sql_query("SELECT * from `table_packages` where special='{$client['location']}'"); $row = sql_fetch_array($res); $packages=$row['id']; { $res2 = sql_query("SELECT * from `table_campaign` banner where packages='{$packages}' order by views_left desc limit 4");{ while($row = sql_fetch_array($res2)) { $banner1= $row['banner']; $views_left = $row['views_left']; $output4 .= '&lt;table width="100%"&gt;&lt;tr&gt;&lt;td style="text-align:left;"&gt;&lt;a href="'.$banner1.'"&gt;'.$banner1.'&lt;/a&gt;&lt;/td&gt;&lt;td style="text-align:right;"&gt;'.$views_left.' '.$stats['views_left'].'&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt; ';} ass(array('title'=&gt;t('abc'), 'content' =&gt; '&lt;div class="toolbar"&gt;'.'&lt;div style="border:0px solid #B2BCA7;margin-bottom:20px;"&gt;&lt;div style="padding: 7px; position: relative;"&gt;'.$output4.'&lt;/div&gt;')); } </code></pre> <p>i simply wanted to show this content </p> <p>sum of table_campaign summation of view left from all row minus tablepage view </p> <p>my tablepage uri column and table_campaign banner column is same .but in tablepage the uri column is unique and it can appear only once but in table_campaign banner column can come several times so i want to add the views_left of all row from table_campaign and compare with tablepage views column .if views column for that particular uri is more than sum of views_left column it will display the output as i have shown . i think i am very clear now</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload