我似乎不能得到grep -v "Africa"在这张表上没有抛出错误,有人可以帮助我在Ubuntu语法?
某个地方有一个错误,我的一个国家没有定义宏观区域(即美洲,非洲,亚洲,欧洲),我找不到它。我需要对这个联接表进行grep,以查看哪个国家只有子区域。
select country, group_concat(region) as regions from regions group by country;
(页脚是这样的)
| Ukraine | Eastern Europe,Europe
| United Arab Emirates | Middle East,Persian Gulf,Western Asia
| United Kingdom | Europe
| United States | Americas,North America
| Uruguay | Americas,South America
| Uzbekistan | Asia,Central Asia
| Vanuatu | Australasia,Melanesia,Oceania
| Venezuela | Amazon,Americas,Andes,South America
| Vietnam | Asia,East Asia,Indochina
| Virgin Islands | Americas,Caribbean
| Wallis and Futuna Islands | Australasia,Oceania,Polynesia
| Yemen | Middle East,Persian Gulf,Western Asia
| Zambia | Africa,Central Africa,East Africa,Southern Africa
| Zimbabwe | Africa,Central Africa,East Africa,Southern Africa
我使用:
mysql -u root -pPASS "use reports"| mysql -u root -pPASS -e "select country, group_concat(region) from regions group by country;"| grep -v 'Africa'
我得到错误:
ERROR 1046 (3D000) at line 1: No database selected
mysql -u root -pPASS reports -e "select country, group_concat(region) as regions from regions group by country;" | grep -v 'Africa'
重要的事情先说:您选择了错误的数据库。数据库名称是一个位置参数;你不需要嵌入SQL语句。
其次,您不能在管道中使用mysql
命令并让第一个命令影响第二个命令,因为在执行第二个语句之前数据库连接是关闭的;它们是完全不同的联系。如果需要多个查询,请在语句内使用分号。上述命令的另一种形式如下所示:
mysql -u root -pPASS -e "use reports; select country, group_concat(region) as regions from regions group by country;" | grep -v 'Africa'