定制订单由 +分组依据

发布于 2024-10-27 20:02:01 字数 373 浏览 0 评论 0原文

所以我在这个表中有一本手册:

id  lang    header_name        text         
1   uk       Youth Development  It's very important
2   dk       tst                hejsa   
3   uk       tst                hello sir

我想进行一个查询来获取给定语言(在本例中为丹麦语)的所有手册条目。如果由于某种原因,原始手册条目(英国的)并未全部 100% 被翻译,我想改为获取英文条目。在这样的表格格式中是否可能?

我猜想这可能是某种“按 header_name 分组”的东西,但不确定。

So I have a manual in this table:

id  lang    header_name        text         
1   uk       Youth Development  It's very important
2   dk       tst                hejsa   
3   uk       tst                hello sir

And I want to make a query that fetches all manual entries for a given language (danish in this case). If for some reason not all 100% of the original manual entries (the UK ones), has been translated I want to get the english entry instead. Is that even possible in table formats such as this?

I guess it would be something with a "group by header_name" of some sorts, but not sure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

温柔嚣张 2024-11-03 20:02:01

试试这个,我没有 SQL,因此没有经过测试
表t1、t2、t3指的是同一个表,使用别名来区分;

select * from t3  
where t3.lang IN ('DK','UK')  
and t3.ID NOT IN  
(select t1.id  
FROM t1,t2  
where t1.header_name = t2.header_name  
AND t2.lang = 'DK'  
AND t1.lang = 'UK'  
)  

本质上,首先您需要找到具有翻译的 ID,然后排除它们。

Try this, i dont have an SQL and hence this is not tested
The tables t1, t2, t3 refer to the same table use an alias to distinguish them;

select * from t3  
where t3.lang IN ('DK','UK')  
and t3.ID NOT IN  
(select t1.id  
FROM t1,t2  
where t1.header_name = t2.header_name  
AND t2.lang = 'DK'  
AND t1.lang = 'UK'  
)  

Essentially first you need to find the ID that have translation, and then exclude them.

⒈起吃苦の倖褔 2024-11-03 20:02:01

这可能可以解决问题,但还没有优化:

SELECT *
FROM the_table
WHERE lang = 'dk'

UNION

SELECT *
FROM the_table
WHERE lang <> 'dk' AND header_name NOT IN (
    SELECT header_name
    FROM the_table
    WHERE lang = 'dk'
)

This might do the trick but it is not optimized:

SELECT *
FROM the_table
WHERE lang = 'dk'

UNION

SELECT *
FROM the_table
WHERE lang <> 'dk' AND header_name NOT IN (
    SELECT header_name
    FROM the_table
    WHERE lang = 'dk'
)
超可爱的懒熊 2024-11-03 20:02:01

我无法发表评论,但我想问的是:
在您刚刚提出的示例中,ID 2 和 ID 3 的行是相同的条目,只是语言不同?

我想说你把它拿出来并制作两个表

Example
id
sort
(all other generic columns)

example_translations
id
example_id
language_id
header_name
text

然后,如果查询 id 1 的示例的丹麦语翻译,它将返回该实体的 example_translations 行。如果没有返回任何内容,您可以查询英文版本。

我认为不可能在 Mysql 级别上做这样的事情

I cant comment but all i want to ask is:
In the example you just put up, the rows with Id 2 and ID 3 are the same entries only different language?

Id say you pull it out and make two tables

Example
id
sort
(all other generic columns)

example_translations
id
example_id
language_id
header_name
text

Then if querying for the danish translation of an example with id 1 it'll return the example_translations row of this entity. if it returns nothing you can query for the english version.

I dont think it is possible to do something like this on Mysql level

苏辞 2024-11-03 20:02:01

按照我的理解,如果丹麦语内容丢失,您想获取英语内容吗?..您可能想在表格中添加一列来标记条目。 (不知道你的“header_name”列是否对你有效,我猜它也会被翻译?..

无论如何,一个名为“entry_id”的列,其中“tst dk”和“tst uk”都有id以“2”为例,您应该在加载手动时询问“entry_id”并首先查找 dk 条目,如果不存在,则加载 uk 条目。

The way i understand this, you want to get the english content if the danish content is missing?.. You might want to add a column to your table where you mark your entries. (dont know if your "header_name" column does that efectly for you, i'm guessing that as well will be translated?..

Anyway, a column named "entry_id" where "tst dk" and "tst uk" would both have id "2" for an example, you should then when you load you manual ask for the "entry_id" and first look for the dk entry, and if it's not there, load the uk entry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文