[英]query using column_name IN ('one','two') grouped by pk and having count (distinct column_name) = 2 returns empty
Using IN to select a dynamic list of software names that a computer must have to be matched, and the data exists in the database for a known value, the result when using: 使用IN选择计算机必须匹配的软件名称的动态列表,并且数据库中存在一个已知值的数据,使用时的结果:
GROUP BY id
HAVING COUNT(DISTINCT column_name) = count_of_list_values;
returns an empty result set when it should be returning the value expected. 当它应该返回期望值时,将返回一个空结果集。 NOTE it works when you are searching for a single list item, this issue is when that list expands to more than one.
注意它在您搜索单个列表项时有效,而该问题在于该列表扩展到多个列表项时。
Plenty of Google searches, resulting in nothing useful... other than that using phpmyadmin, i have been trying to figure out why it is failing. 大量的Google搜索,除了使用phpmyadmin之外,没有其他有用的结果,我一直在试图弄清为什么它失败了。
Isolated the area where it seems to choking and trying different things with the query to try to get it to work. 隔离看起来似乎令人窒息的区域,并尝试使用查询进行其他操作以使其正常工作。
this is the section of the query that i am using. 这是我正在使用的查询部分。
SELECT
am_software_archive.asset_name
FROM
am_software_archive
WHERE
LOWER(am_software_archive.sw_name) IN('nodejs', 'visio 2013')
GROUP BY
am_software_archive.id
HAVING
COUNT(
DISTINCT am_software_archive.sw_name
) = 2
The data in this table exists and is valid so it should work... The table definition 该表中的数据存在并且有效,因此应该可以使用...表定义
CREATE TABLE IF NOT EXISTS am_software_archive(
id BIGINT NOT NULL UNIQUE,
asset_name VARCHAR(10) NOT NULL,
sw_name VARCHAR(150) NOT NULL,
sw_developer BIGINT NOT NULL,
sw_key VARCHAR(50) DEFAULT NULL,
sw_osver VARCHAR(15) DEFAULT NULL,
CONSTRAINT PK_software PRIMARY KEY(id, asset_name),
INDEX idx_sw_name_asset(asset_name,sw_name),
INDEX idx_sw_key_asset_name(asset_name,sw_key),
INDEX idx_sw_name_sw_key(sw_name,sw_key),
INDEX idx_osver_sw_name(sw_name,sw_osver),
INDEX idx_osver_asset_name(asset_name,sw_osver)
)
In my database the expected result would be: "ABX50269" 在我的数据库中,预期结果将是:“ ABX50269”
Actual results well are empty, but shouldn't be. 实际结果是空的,但不应该这样。
You group by the id
, which is unique so there cannot ever be two or more (different) sw_name
per id
. 您按
id
分组,该id
是唯一的,因此每个id
不能有两个或多个(不同的) sw_name
。
As asset_name
is the column in the list for SELECT
, I think you actually want to group by asset_name
. 由于
asset_name
是SELECT
列表中的列,我认为您实际上是想按asset_name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.