Guest User

Untitled

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