从MySQL数据库中的相同记录中选择特定记录

时间:2012-12-29 20:17:55

标签: mysql

我有一张这样的表:

+---------+---------+-----------------------------------------+
| type    | city    | name                                    |
+---------+---------+-----------------------------------------+
| cricket | kolkata | Khadim's Ashok Malhotra Cricket Academy |
| cricket | kolkata | Calcutta Cricket Coaching Center (C4)   |
| cricket | kolkata | Sambaran Banerjee Cricket academy       |
| cricket | kolkata | Bournvita cricket acadamemy of arun lal |
| cricket | kolkata | friends of the stadium                  |
| cricket | kolkata | pankaj roy cricket academy              |
| cricket | kolkata | sunil gavaskar cricket foundation       |
| cricket | kolkata | castlewood india                        |
| cricket | kolkata | GK sports                               |
| cricket | kolkata | NULL                                    |
| cricket | kolkata | NULL                                    |
| cricket | kolkata | NULL                                    |
| cricket | kolkata | NULL                                    |
| cricket | kolkata | NULL                                    |
| cricket | kolkata | NULL                                    |
+---------+---------+-----------------------------------------+

我想提供不同的名称而不是NULL,我该怎么做?

2 个答案:

答案 0 :(得分:0)

尝试IFNULL

Select IFNULL(name,'Jon Smith') as name from myTable

如果您希望在名称中的值为null时使用该研究所的名称 你可以::

Select IFNULL(name,institute) as name from myTable

答案 1 :(得分:0)

您也可以使用它:

name

开始
select * from table_name where name like "Cricket%"

包含任何

select * from table_name where name like "%Cricket%"

结尾
select * from table_name where name like "%Cricket"