Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .<?php
- $servername = "localhost";
- $username = "root";
- $password = "jit123";
- $dbname = "db5";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error)
- {
- die("connection failed: " . $conn->connect_error);
- }
- else
- {
- echo"<p align=\"center\"><b>1.Find all customers who have atleast 2 accounts at the main branch<br><br></b>";
- echo"<p align=\"center\"><b>QUERY :</b> select d.cname from depositor d,account a where d.accno=a.accno group by d.cname having count(d.cname)>=2;<br><br>";
- $sqlQuery = "select d.cname from depositor d,account a where d.accno=a.accno group by d.cname having count(d.cname)>=2;";
- $result = $conn->query($sqlQuery);
- if($result->num_rows > 0)
- {
- echo "<table align=\"center\"border=10><tr><th>CName</th>";
- echo "</tr>";
- while($row = $result->fetch_assoc())
- {
- echo"<tr>";
- echo "<td>$row[cname]</td>";
- echo "</tr>";
- }
- echo "</table><br><br><br>";
- }
- else
- echo"Empty set";
- 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>";
- echo "<p align=\"center\"><b>QUERY :</b> select d.cname,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.cname having count(distinct b.branchname)=(select count(distinct b.branchname) from branch b where b.branchcity='bangalore');<br><br>";
- $sqlQuery = "select d.cname,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.cname having count(distinct b.branchname)=(select count(distinct b.branchname) from branch b where b.branchcity='bangalore')";
- $result = $conn->query($sqlQuery);
- if($result->num_rows > 0)
- {
- echo "<table align=\"center\"border=10><tr><th>CName</th>";
- echo "<th>Count branchname</th>";
- echo "</tr>";
- while($row = $result->fetch_assoc())
- {
- echo"<tr>";
- echo "<td>$row[cname]</td>";
- echo"<td>$row[cnt]</td>";
- echo "</tr>";
- }
- echo "</table><br><br><br>";
- }
- else
- echo"Empty set";
- $sqlQuery="delete from account where bname in(select bname from branch where bcity='mumbai')";
- $result=$conn->query($sqlQuery);
- 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>";
- echo "<p align=\"center\"><b>QUERY :</b>delete from account where bname in(select bname from branch where bcity='mumbai')<br><br></b>";
- $sqlQuery="select * from account";
- $result=$conn->query($sqlQuery);
- if($result->num_rows > 0)
- {
- echo "<table align=\"center\"border=10><tr><th>Account Number</th>";
- echo "<th>Branch Name</th>";
- echo "<th>Balance</th>";
- echo "</tr>";
- while($row = $result->fetch_assoc())
- {
- echo"<tr>";
- echo "<td>$row[accno]</td>";
- echo"<td>$row[branchname]</td>";
- echo"<td>$row[balance]</td>";
- echo "</tr>";
- }
- echo "</table>";
- }
- else
- echo"Empty set";
- }
- $conn->close();
- ?>
Add Comment
Please, Sign In to add comment