SQL查询帮助(我正在努力学习)

时间:2015-06-07 09:52:23

标签: sql

我需要帮助

我有桌面世界(名称,大陆,首都),我不知道如何做到这一点:

  1. 找到首都是国家的国家加上“城市”。
  2. 找到两个“o”字符分隔的国家/地区。
  3. 查找名称中包含三个或更多a的国家/地区。
  4. 找出首都和国家名称扩展名称的名称。
  5. 非常感谢脸红

4 个答案:

答案 0 :(得分:0)

在有问题的页面上,您的第一个问题是12号。这是他们给你的开始:

source [file]

此外,在textarea上方,他们提到了SELECT name, concat(name, 'town') FROM world WHERE name LIKE '%ina%' 。对于问题12,其中资本是国家的名称加上单词" City",您的where子句将是:

the concat function

注意单词City之前的前导空格。这应该让你继续其余的。

答案 1 :(得分:0)

1. SELECT name FROM world WHERE capital=concat(name,' city');

2. SELECT name FROM world WHERE name LIKE '%o__o%';

4. SELECT name,mid(capital,LENGTH(name)+1) rep
         FROM world
             WHERE capital LIKE concat(name,'_%');

   one more method for ques number 4 using REPLACE SQL FUNCTION: OR

  SELECT name,replace(capital,name,'') rep
            FROM world
                  WHERE capital LIKE concat(name,'_%')

答案 2 :(得分:0)

1.SELECT name FROM world WHERE capital LIKE concat(name, '%','City');

2.SELECT name FROM world WHERE name LIKE '%o__o%';

3.SELECT name FROM world WHERE name LIKE '%a%a%a%';

4.SELECT name, capital FROM world WHERE capital LIKE concat(name, '_%');

答案 3 :(得分:0)

这有效

{
    "_id" : ObjectId("56587befdb7224110f007233"),
    "comments" : [
        {
            "user_id" : ObjectId("562fa014888806820e21e0df"),
            "user_full_name" : "Niroj Paudel",
            "comment" : "wat a nice car wow",
            "_id" : ObjectId("565efa37635f09900d21a33a"),
            "dt" : ISODate("2015-12-02T14:03:35.289Z")
        },
        {
            "user_id" : ObjectId("562fa014888806820e21e0df"),
            "user_full_name" : "Niroj Paudel",
            "comment" : "love is life budikhola ma dives",
            "_id" : ObjectId("565efa76635f09900d21a33b"),
            "dt" : ISODate("2015-12-02T14:04:38.661Z")
        },
        {
            "user_id" : ObjectId("562fa014888806820e21e0df"),
            "user_full_name" : "Niroj Paudel",
            "comment" : "bholi ajaya ko bihe",
            "_id" : ObjectId("565efaa0635f09900d21a33c"),
            "dt" : ISODate("2015-12-02T14:05:20.847Z")
        },
        {
            "user_id" : ObjectId("562fa014888806820e21e0df"),
            "user_full_name" : "Niroj Paudel",
            "comment" : "manish is nice",
            "_id" : ObjectId("565efb17635f09900d21a33d"),
            "dt" : ISODate("2015-12-02T14:07:19.704Z")
        },
        {
            "user_id" : ObjectId("562fa014888806820e21e0df"),
            "user_full_name" : "Niroj Paudel",
            "comment" : "niroj is cool",
            "_id" : ObjectId("565efd53c22dddc80e8f461c"),
            "dt" : ISODate("2015-12-02T14:16:51.730Z")
        },
        {
            "user_id" : ObjectId("562fa014888806820e21e0df"),
            "user_full_name" : "Niroj Paudel",
            "comment" : "ramesh is cool",
            "_id" : ObjectId("565f0d376d82e24c11f6c0d1"),
            "dt" : ISODate("2015-12-02T15:24:39.010Z")
        },
        {
            "user_id" : ObjectId("562fa014888806820e21e0df"),
            "user_full_name" : "Niroj Paudel",
            "comment" : "pradip is bhole baba",
            "_id" : ObjectId("565f0f5d77f0c7bd11bbadd9"),
            "dt" : ISODate("2015-12-02T15:33:49.578Z")
        },
        {
            "user_id" : ObjectId("562fa014888806820e21e0df"),
            "user_full_name" : "Niroj Paudel",
            "comment" : "honkog pokhara... he he ha ha",
            "_id" : ObjectId("565f1034fd07cbfc1129db0b"),
            "dt" : ISODate("2015-12-02T15:37:24.581Z")
        }
    ]
}

有没有人有更有说服力的方法来做到这一点?