匹配一行内的不同值 [英] Matching Different Value within One Row
问题描述
我想执行一个查询,借此我想检查 A 列上是否有某些值.A 可以只有 X 、 X 和 Y 或 X Y 和 Z 的组合.
I want to perform a query whereby I want to check whether on the columns A has either certain values. A could have only X , X and Y or a combination of X Y and Z.
为了更好地理解.我正在表中检查一本书的作者.该表具有 BOOK_ID 、 BOOK_TITLE 、 AUTHOR_NAME 和 AUTHOR_ORDER.
To give a better understanding. I am checking a book's author within a table itself. The table has the BOOK_ID , BOOK_TITLE , AUTHOR_NAME, AUTHOR_ORDER.
因此一本书可能有 1,2 或 3 个作者,按顺序在 AUTHOR_ORDER 行中列出.我非常努力地达到一个输出,如果一本书有 3 个作者,它将相应地从第一作者到第三作者显示.我现在被困在需要比较值并将其显示在输出中的部分.
So a book might have 1,2 or 3 authors, listed in order written inside the AUTHOR_ORDER row. I am trying very hard to reach an output where if a book has 3 authors, it will display accordingly from the first author to the third author. I am now stuck in the part where I need to compare the value and present it in the output.
知道如何在 MYSQL 输出中实现这一点吗?
Any idea how to achieve this in MYSQL output?
示例:
输出结果大致是这样的:
The output result is more or less like this:
如果标题的 au_ord 为 1,2 和 3,则应有一个新列,所有作者姓名都按升序排列.
If the title has au_ord of 1,2 and 3, there shall be a new column with all the authors name listed in ascending.
例如,对于标题 BU1032,作者行将是 Bennet, Green
推荐答案
我认为 GROUP_CONCAT
是您所追求的:
I think GROUP_CONCAT
is what you are after:
SELECT Title_ID,
Title,
GROUP_CONCAT(au_LName ORDER BY au_Ord) AS Authors
FROM Books
GROUP BY Title_ID, Title;
这篇关于匹配一行内的不同值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!