Guest User

Untitled

a guest
Nov 2nd, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.20 KB | None | 0 0
  1. <?php
  2. $servername ="localhost";
  3. $username="root";
  4. $password="jit123";
  5. $dbname="1jt14cs007db5";
  6.  
  7. $conn= new mysqli($servername,$username,$password,$dbname);
  8.  
  9. if($conn->connect_error)
  10.     {
  11.         die("CONN failed :" . $conn->connect_error);
  12.     }
  13. else
  14.     {
  15.        
  16.         $sqlquery="select d.customername
  17.                    from depositor d, account a
  18.                    where d.accno=a.accno
  19.                    group by d.customername having count(d.customername)>=2;";
  20.                    
  21.         $result = $conn->query($sqlquery);
  22.        
  23.         if($result->num_rows>0)
  24.         {
  25.             echo "<p align=\"center\"><b>1. Find all the customers who have at least two accounts at the Main branch</b><br>";
  26.             echo "<br>select d.customername<br>
  27.                    from depositor d, account a<br>
  28.                    where d.accno=a.accno<br>
  29.                    group by d.customername having count(d.customername)>=2;</p>";
  30.             echo "<table align=\"center\"border=1> <tr> <th> Customer Name </th> </tr>";
  31.             while($row=$result->fetch_assoc())
  32.             {
  33.                
  34.                 echo "<tr><td>$row[customername]</td></tr>";
  35.                
  36.             }
  37.             echo "</table>";
  38.         }
  39.         else echo "Empty Set";
  40.        
  41.        
  42.         $sqlquery="select d.customername , count(distinct b.branchname) as cnt
  43.         from account a, depositor d, branch b
  44.         where a.accno=d.accno and b.branchname =a.branchname and b.branchcity='bangalore'
  45.         group by d.customername having count(distinct b.branchname) = (select count(distinct b.branchname)
  46.         from branch b where b.branchcity='bangalore');";
  47.                    
  48.         $result = $conn->query($sqlquery);
  49.        
  50.         if($result->num_rows>0)
  51.         {
  52.             echo "<p align=\"center\"><b>2. Find all the customers who have an account at all the branches located in a specific city</b><br>";
  53.             echo "<br>select d.customername , count(distinct b.branchname) as cnt<br>
  54.             from account a, depositor d, branch b<br>
  55.             where a.accno=d.accno and b.branchname =a.branchname and b.branchcity=\"bangalore\"<br>
  56.             group by d.customername having count(distinct b.branchname) = (select count(distinct b.branchname)<br>
  57.             from branch b where b.branchcity=\"bangalore\");</p>";
  58.        
  59.             echo "<table align=\"center\"border=1> <tr> <th> Customer Name </th> <th> Count </th> </tr>";
  60.             while($row=$result->fetch_assoc())
  61.             {
  62.                
  63.                 echo "<tr><td>$row[customername]</td><td>$row[cnt]</td></tr>";
  64.                
  65.             }
  66.             echo "</table>";
  67.         }
  68.         else echo "Empty Set";
  69.        
  70.         /*$sqlquery="select d.customername , count(distinct b.branchname) as cnt
  71.         from account a, depositor d, branch b
  72.         where a.accno=d.accno and b.branchname =a.branchname and b.branchcity='bangalore
  73.         group by d.customername having count(distinct b.branchname) = (select count(distinct b.branchname)
  74.         from branch b where b.branchcity='bangalore');";
  75.                    
  76.         $result = $conn->query($sqlquery);
  77.        
  78.         if($result->num_rows>0)
  79.         {
  80.             echo "<p align=\"center\"><b>3. Demonstrate how you delete all account tuples at every branch located in a specific city</b><br>";
  81.             echo "<br></p>";
  82.        
  83.             echo "<table align=\"center\"border=1> <tr> <th> Customer Name </th> <th> Count </th> </tr>";
  84.             while($row=$result->fetch_assoc())
  85.             {
  86.                
  87.                 echo "<tr><td>$row[customername]</td><td>$row[cnt]</td></tr>";
  88.                
  89.             }
  90.             echo "</table>";
  91.         }
  92.         else echo "Empty Set";*/
  93.        
  94.     }
  95.    
  96.  
  97. $conn->close();
  98. ?>
Add Comment
Please, Sign In to add comment