SQL练习_1

1.

“Mexico 墨西哥” 的首都是”Mexico City”。

顯示所有國家名字,其首都是國家名字加上”City”。

concat 函數:函數 concat 可以用來合拼兩個或以上的字串

SELECT name 
FROM world 
WHERE capital LIKE concat(name, ' City')

2.

找出所有首都和其國家名字,而首都要有國家名字中出現。

select capital, name
from world
where capital like concat('%',name,'%')

3.

找出所有首都和其國家名字,而首都是國家名字的延伸。
你應顯示 Mexico City, 因它比其國家名字 Mexico 長。
你不應顯示 Luxembourg, 因它的首都和國家名相是相同的。

select name, capital
from world
where capital like concat(name,'%') and capital != name

比名字长,不能一样,得用and并列。

4.

"Monaco-Ville" 是合併國家名字 "Monaco" 和延伸詞 "-Ville".

顯示國家名字,及其延伸詞,如首都是國家名字的延伸。

你可以使用 SQL 函數 REPLACE 或 MID.

select name,replace(capital,name,'') as name_1
from world 
where capital like concat(name,'_%')

replace 函数:

REPLACE(f, s1, s2) returns the string f with all occurances of s1 replaced with s2.

例 1:

replace('vessel','e','a') <- 'vassal'

用空字符代替name,然后把这一列设为name1

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您想在Vue.js和Django实现所有国家地区选择,可以考虑以下方案: 1. 在Django使用django-countries和django-cities插件来获取国家和城市信息。您可以在Django定义模型类来表示国家和城市信息,然后使用ORM框架来进行增删改查等操作。例如: ```python from django_countries.fields import CountryField from cities.models import City, Country class UserProfile(models.Model): # ... country = CountryField() city = models.ForeignKey(City, on_delete=models.PROTECT) # ... ``` 2. 在Vue.js使用第三方的国家地区选择组件,例如vue-country-region-select、vue-area-linkage等,或者自己编写组件来实现。在组件,您可以使用axios来向Django发送请求,获取国家和城市信息。例如: ```vue <template> <div> <select v-model="selectedCountry" @change="getCities"> <option v-for="country in countries" :value="country.code">{{ country.name }}</option> </select> <select v-model="selectedCity"> <option v-for="city in cities" :value="city.id">{{ city.name }}</option> </select> </div> </template> <script> import axios from 'axios'; export default { data() { return { countries: [], cities: [], selectedCountry: '', selectedCity: '', }; }, methods: { getCountries() { axios.get('/api/countries/') .then(response => { this.countries = response.data; }) .catch(error => { console.log(error); }); }, getCities() { axios.get(`/api/cities/?country=${this.selectedCountry}`) .then(response => { this.cities = response.data; }) .catch(error => { console.log(error); }); }, }, mounted() { this.getCountries(); }, }; </script> ``` 在这个示例,我们使用了Vue.js的select元素来实现国家和城市选择。在mounted生命周期,我们使用axios向Django发送请求,获取所有国家的信息。当用户选择一个国家时,我们使用axios再次向Django发送请求,获取该国家的城市信息。然后将这些信息绑定到select元素的选项。 希望这个方案能对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值