Guest User

Untitled

a guest
Nov 2nd, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.18 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="delete from account where branchname in ( select branchname from branch where branchcity=‘mumbai‘);";           
  71.         $result = $conn->query($sqlquery);
  72.        
  73.         $sqlquery="select * from account";
  74.         $result = $conn->query($sqlquery);
  75.        
  76.         if($result->num_rows>0)
  77.         {
  78.             echo "<p align=\"center\"><b>3. Demonstrate how you delete all account tuples at every branch located in a specific city</b><br>";
  79.             echo "<br>delete from account where branchname in ( select branchname from branch where branchcity=‘mumbai‘);</p>";
  80.        
  81.             echo "<table align=\"center\"border=1> <tr> <th> Account Number </th> <th> Branch Name </th> <th> Balance </th></tr>";
  82.             while($row=$result->fetch_assoc())
  83.             {
  84.                
  85.                 echo "<tr><td>$row[accno]</td><td>$row[branchname]</td><td>$row[balance]</td</tr>";
  86.                
  87.             }
  88.             echo "</table>";
  89.         }
  90.         else echo "Empty Set";
  91.        
  92.     }
  93.    
  94.  
  95. $conn->close();
  96. ?>
Add Comment
Please, Sign In to add comment