0% found this document useful (0 votes)
22 views3 pages

Views Asig2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Views Asig2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q2:Person-area databases

Consider following entities and theire relations:


postgres=# select * from perso;
pno | pname | bday | income_money
-----+--------+------------+--------------
1 | tupe | 1998-09-20 | 500000
2 | kamble | 1989-06-20 | 50000
2 | kamble | 1999-11-02 | 10000
(3 rows)
postgres=# select * from areaa;
aname | atype | pno
----------+-------+-----
hardpsar | rural | 1
katraj | rural | 2
thane | urban | 3
(3 rows)

Query1: display all person contain word like “tupe” in


name living in Hadpsar area.
MariaDB [test]> create view nam_tupe as select pname,aname
from person,area where aname='hadpsar' and pname like'%tupe';
Query OK, 0 rows affected (0.022 sec)
MariaDB [test]> select * from nam_tupe;
+-----+---------+
| pname | aname |
+-------+---------+
| tupe | hadpsar |
+-------+---------+
1 row in set (0.005 sec)
Query2: Count the all persons living in rural area having
income more than 10000.
MariaDB [test]> create view count_of_rural as select
count(pname) from person,area where person.pno=area.pno and
atype='rural' and income_money>10000;
MariaDB [test]> select * from cout_of_rural;
+--------------+
| count(pname) |
+--------------+
| 2 |
+--------------+
1 row in set (0.150 sec)
Query3: display area wise count of pepole having age
more than 60.
MariaDB [test]> create view age_limit_areawis as select
person.pno,area.atype,count(person.pno) from area,person where
person.pno=area.pno and bday>'1989.06.20' group by atype;
Query OK, 0 rows affected (0.034 sec)
MariaDB [test]> select * from age_limit_areawis;
+------+-------+-------------------+
| pno | atype | count(person.pno) |
+------+-------+-------------------+
| 2 | rural | 2|
+------+-------+-------------------+
1 row in set (0.039 sec)
Query4: Display area and person name having maxim
income, shorted by area name.
MariaDB [test]> create view max_income as select aname,pname
from area,person where person.pno=area.pno and income_money
in(select max(income_money) from person) order by aname;
Query OK, 0 rows affected (0.124 sec)
MariaDB [test]> select * from max_income;
+-------+-------+
| aname | pname |
+-------+-------+
| hadpsar | tupe |
+-------+-------+
1 row in set (0.050 sec)

You might also like