我需要以下正确的查询

时间:2019-03-29 22:24:46

标签: sql sql-server

这是“客户”表

#include "stdafx.h"
#include <iostream>
using namespace std;

int searchArray(int a[], int x) {
    for (int i = 0; i < a[100]; i++) {
        if (x == a[i])
            return i + 1;
        break;
    }
    return -1;
}

int main()
{
    int wait, x, y, a[100];

    //problem 3
    cout << "Enter the size of the array(1-100): ";
    cin >> y;

    for (int i = 0; i < y; i++) {
        cout << "Enter an array of numbers:";
        cin >> a[i];
    }
    searchArray(a[100], x); //i get error on this line with a[100]

    cin >> wait;

    return 0;
}

需要查询以显示每个国家/地区的客户数量。 GB和英国应视为一个国家。

1 个答案:

答案 0 :(得分:3)

使用CASE表达式:

SELECT (CASE WHEN country = 'GB' THEN 'UK' ELSE country END) as country,
       COUNT(*), Country
FROM Customer
GROUP BY (CASE WHEN country = 'GB' THEN 'UK' ELSE country END);