如何在MYSQL中创建此查询?加入是什么?

时间:2016-10-04 16:04:41

标签: mysql join

i cannot create this kind of join

我的MySQL数据库上有两个表,一个用于身份记录,另一个表用于,我知道如何创建内部,左,右连接等连接但我不知道如何创建一个将合并的连接它们

enter image description here

3 个答案:

答案 0 :(得分:4)

不是联接不同,您需要使用group by子句和group_concat()函数在record字段中生成预期结果输出。无论是两个表之间的左连接还是内连接,您都可以自行决定。根据示例数据,内部联接可以正常工作:

SELECT a.id_tag, a.Name, group_concat(b.Record) as record
FROM table1 a INNER JOIN table2 b ON a.id_tag = b.id_tag
group by a.id_tag, a.Name

答案 1 :(得分:1)

看看

Ramda REPL

http://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html

SELECT a.id_tag, a.Name, GROUP_CONCAT(b.Record) as Records FROM tablea a LEFT JOIN tableb b ON a.id_tag = b.id_tag GROUP BY b.Record;

要整理记录并使其更整洁,您可能需要查看

COALESCE

http://www.w3resource.com/mysql/aggregate-functions-and-grouping/aggregate-functions-and-grouping-group_concat.php

答案 2 :(得分:0)

public void toggleHideyBar() {
    // The UI options currently enabled are represented by a bitfield.
    // getSystemUiVisibility() gives us that bitfield.
    int uiOptions = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    int newUiOptions = uiOptions;
    boolean isImmersiveModeEnabled =
            ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
    if (isImmersiveModeEnabled) {
        Log.i(TAG, "Turning immersive mode mode off. ");
    } else {
        Log.i(TAG, "Turning immersive mode mode on.");
    }

    // Immersive mode: Backward compatible to KitKat (API 19).
    // Note that this flag doesn't do anything by itself, it only augments the behavior
    // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample
    // all three flags are being toggled together.
    // This sample uses the "sticky" form of immersive mode, which will let the user swipe
    // the bars back in again, but will automatically make them disappear a few seconds later.
    newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
    newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    getActivity().getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}