Saturday 16 July 2011

Database - mysql queries -part3

 
  Enter password: *****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9 to server version: 5.0.27-community-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use adi
Database changed
mysql> select *
    -> from customer;
+---------+-----------+---------------+----------+----------+---------------+---
-------+--------------+--------+
| Cust_No | Cust_Name | Street        | State    | Zip_Code | City          | Ba
lance  | Credit_Limit | Rep_No |
+---------+-----------+---------------+----------+----------+---------------+---
-------+--------------+--------+
| 148     | Mohd Zaid | Jln Merbuk    | Selangor |    58000 | Kota Lama     |  6
550.00 |      7500.00 | 20     |
| 282     | Fikri     | Wangsa Maju   | KL       |    53300 | Wangsa Maju   |
431.00 |     10000.00 | 35     |
| 356     | Azwa      | Setia Wangsa  | KL       |    54200 | Setia Wangsa  |  5
785.00 |      7500.00 | 65     |
| 408     | Bul       | Taiping       | Perak    |    34600 | Kamunting     |  5
285.00 |      5000.00 | 35     |
| 462     | Afzal     | SD            | Selangor |    52000 | Damansara     |  3
412.00 |     10000.00 | 65     |
| 524     | Shame     | Jln Laksamana | Perak    |    36000 | Teluk Intan   | 12
762.00 |     15000.00 | 20     |
| 608     | Lina      | Taiping       | Perak    |    36000 | Teluk Intan   |  2
106.00 |     10000.00 | 65     |
| 687     | Jack      | Kuching       | Serawak  |    26000 | kuching       |  2
851.00 |      5000.00 | 35     |
| 725     | Man       | Machang       | Kelantan |    18300 | Taman Permata |
248.00 |      7500.00 | 35     |
| 842     | Adi       | Kuala Krai    | Kelantan |    18000 | Kg Enggong    |  8
221.00 |      7500.00 | 20     |
+---------+-----------+---------------+----------+----------+---------------+---
-------+--------------+--------+
10 rows in set (0.00 sec)

mysql> select Cust_No, cust_Name, Balance from customer;
+---------+-----------+----------+
| Cust_No | cust_Name | Balance  |
+---------+-----------+----------+
| 148     | Mohd Zaid |  6550.00 |
| 282     | Fikri     |   431.00 |
| 356     | Azwa      |  5785.00 |
| 408     | Bul       |  5285.00 |
| 462     | Afzal     |  3412.00 |
| 524     | Shame     | 12762.00 |
| 608     | Lina      |  2106.00 |
| 687     | Jack      |  2851.00 |
| 725     | Man       |   248.00 |
| 842     | Adi       |  8221.00 |
+---------+-----------+----------+
10 rows in set (0.00 sec)

mysql> select Cust_Name from customer where cust_No='687';
+-----------+
| Cust_Name |
+-----------+
| Jack      |
+-----------+
1 row in set (0.00 sec)

mysql> select Cust_Name from customer where rep_No='35';
+-----------+
| Cust_Name |
+-----------+
| Fikri     |
| Bul       |
| Jack      |
| Man       |
+-----------+
4 rows in set (0.00 sec)

mysql> select Cust_Name from customer where balance>=credit_limit;
+-----------+
| Cust_Name |
+-----------+
| Bul       |
| Adi       |
+-----------+
2 rows in set (0.00 sec)

mysql> select Cust_name, City from customer where Balance<='400';
+-----------+---------------+
| Cust_name | City          |
+-----------+---------------+
| Man       | Taman Permata |
+-----------+---------------+
1 row in set (0.00 sec)

mysql> select Cust_name, Cust_No, (credit_Limit-Balance) from customer;
+-----------+---------+------------------------+
| Cust_name | Cust_No | (credit_Limit-Balance) |
+-----------+---------+------------------------+
| Mohd Zaid | 148     |                 950.00 |
| Fikri     | 282     |                9569.00 |
| Azwa      | 356     |                1715.00 |
| Bul       | 408     |                -285.00 |
| Afzal     | 462     |                6588.00 |
| Shame     | 524     |                2238.00 |
| Lina      | 608     |                7894.00 |
| Jack      | 687     |                2149.00 |
| Man       | 725     |                7252.00 |
| Adi       | 842     |                -721.00 |
+-----------+---------+------------------------+
10 rows in set (0.00 sec)

No comments:

Post a Comment