以下是我的产品实体表
我想从table中获取数据,其中user_id不应该等于12,36,43
如何为其编写选择查询
当前的SQL查询 -
从catalog_product_entity中选择*,其中entity_id = 12345;
我想要没有user_id 12,36,43的结果
desc catalog_product_entity;
+------------------+----------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------------------+------+-----+---------------------+----------------+
| entity_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| entity_type_id | smallint(8) unsigned | NO | MUL | 0 | |
| attribute_set_id | smallint(5) unsigned | NO | MUL | 0 | |
| type_id | varchar(32) | NO | | simple | |
| sku | varchar(64) | YES | MUL | NULL | |
| created_at | datetime | NO | | 0000-00-00 00:00:00 | |
| updated_at | datetime | NO | | 0000-00-00 00:00:00 | |
| has_options | smallint(1) | NO | | 0 | |
| required_options | tinyint(1) unsigned | NO | | 0 | |
| user_id | mediumint(11) | NO | | NULL | |
+------------------+----------------------+------+-----+---------------------+----------------+
从catalog_product_entity中选择不同的user_id;
+---------+
| user_id |
+---------+
| 8 |
| 4 |
| 9 |
| 1 |
| 12 |
| 10 |
| 13 |
| 15 |
| 7 |
| 33 |
| 34 |
| 35 |
| 36 |
| 43 |
| 38 |
| 49 |
| 39 |
+---------+
答案 0 :(得分:1)
尝试此查询:
id:= "ket"
c.EnsureIndexKey("hobby")
err = c.Find(bson.M{"$hobby": bson.M{"$search": id,},}).All(&result)
答案 1 :(得分:0)
使用WHERE ... NOT IN
:
SELECT * FROM catalog_product_entity
WHERE entity_id = 12345 AND
user_id NOT IN (12, 36, 43)
答案 2 :(得分:0)
试试这个
select * from catalog_product_entity where user_id not in (12,36,43) and entity_id = 12345 order by desc
答案 3 :(得分:0)
不在:
select *
from catalog_product_entity
where entity_id = 12345
and user_id not in (12, 36, 43);