选择Distinct操作数应包含1列

时间:2016-07-21 02:49:01

标签: mysql sql

的MySQL> select * from product;

    +----+-------------+-------+---------------------+----------+
    | id | prod        | code  | name                | prodstat | 
    +----+-------------+-------+---------------------+----------+
    |  1 | ACCESSORIES | 2810  | Dish Rack           | 1        |
    |  2 | ACCESSORIES | 2816  | Saucer Rack         | 1        |
    |  3 | ACCESSORIES | 2830  | Drying Crate        | 1        |
    |  4 | ACCESSORIES | 2820  | Big Crate Cover     | 1        |
    |  5 | ACCESSORIES | 2826  | Scallop Crate Cover | 1        |
    |  6 | ACCESSORIES | 2828  | Mini Crate Cover    | 1        | 
    |  7 | ACCESSORIES | 2839  | Small Goblet Cover  | 1        |
    |  8 | ACCESSORIES | 2878  | Harvest Crate Cover | 1        |
    |  9 | CRATES      | 1688N | Big Crate New       | 1        |
    +----+-------------+-------+---------------------+----------+
    9 rows in set (0.00 sec)
     select distinct(prod, code, name) as Prod from product;
ERROR 1241 (21000): Operand should contain 1 column(s)

需要结果如:

|Prod|
|ACCESSORIES 2810 Dish Rack|

2 个答案:

答案 0 :(得分:1)

删除括号:

driver.findElement(By.linkText("x")).click();
driver.findElement(By.cssSelector("#request-types-table a.aui-restfultable-delete-small").click();

select distinct prod, code, name from product; 不是一个函数。 distinct是一个子句,select distinct适用于所有参数。

如果您想将这三列合并为一列,请使用distinctconcat()

concat_ws()

(可能没有select distinct concat_ws(' ', prod, code, name) as Prod from product; 。)

答案 1 :(得分:0)

追加列并提供别名

select distinct (prod+' '+ code+' '+ name) as Prod from product;