[英]How to find out the values from a specific column in the results of a MySQL query?
I have a table with the following columns: id, firstname, lastname, category. 我有一个包含以下列的表格:ID,名字,姓氏,类别。 And let's say i have data with categories like: action, comedy, drama, horror. 假设我有以下类别的数据:动作,喜剧,戏剧,恐怖。 My query is 我的查询是
SELECT * FROM tablename WHERE firstname LIKE '%John%'
The query will bring all the records that contain 'John' in firstname, and let's assume that the records have different values for categoty: action and comedy only. 该查询将带所有名字中包含“ John”的记录,并假设这些记录的类别值不同:仅动作和喜剧。
How to find out the list with all the values available in category column for this specific search. 如何针对此特定搜索在类别列中找到所有可用值的列表。
Thanks! 谢谢!
如果您想要一个不同的类别列表,则名字类似于John:
SELECT DISTINCT category FROM tablename WHERE firstname LIKE '%John%'
try this: 尝试这个:
SELECT *
FROM tablename
WHERE firstname LIKE '%John%'
and category='category_name'
SELECT category FROM tablename WHERE firstname LIKE '%John%'
看起来很简单
如果您希望类别列表中包含出现次数:
SELECT DISTINCT CATEGORY, COUNT(*) AS Total FROM tablename WHERE firstname LIKE '%John%' GROUP BY CATEGORY ORDER BY CATEGORY
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.