Microsoft SQL代码在转换为MySQL时无法运行

oknwwptz  于 2022-12-10  发布在  Mysql
关注(0)|答案(1)|浏览(110)

我有一段Microsoft SQL代码,我正试图在MySQL(MariaDB 5.5.68)中使用。我尝试了一千种方法,但都无济于事。

SELECT t.title_id, t.title_name, p.pub_name,
    select a.au_fname + ' ' + a.au_lname from authors a
    join title_authors ta on a.au_id = ta.au_id
    where ta.au_order = 1 and ta.title_id = t.title_id)
    as author_1, isnull ((
    select a.au_fname + ' ' + a.au_lname from authors a
    join title_authors ta on a.au_id = ta.au id
    where ta.au_order = 2 and ta.title_id = t.title_id), '')
    as author_2, isnull((
    select a.au_fname + ' ' + a.au_lname from authors a
    join title_authors ta on a.au_id = ta.au_id
    where ta.au_order = 3 and ta.title_id = t.title_id), '')
    as author_3 from titles t
    join publishers p
    on p.pub_id = t.pub_id;

请救救我!

SELECT t.title_id, t.title_name, p.pub_name,
    (SELECT CONCAT(a.au_fname, ' ', a.au_lname)
        from authors a
        JOIN title_authors ta ON a.au_id = ta.au_id
        WHERE ta.au_order = 1 and ta.au_id = t.title_id) as author_1,
    ISNULL((
        SELECT CONCAT(a.au_fname, a.au_lname)
        from authors a
        JOIN title_authors ta ON a.au_id = ta.au_id
        WHERE ta.au_order = 2 and ta.au_id = t.title_id),'') as author_2,
    ISNULL((
        SELECT CONCAT(a.au_fname, a.au_lname)
        from authors a
        JOIN title_authors ta ON a.au_id = ta.au_id
        WHERE ta.au_order = 3 and ta.au_id = t.title_id),'') as author_3
FROM titles t
JOIN publishers p
ON p.pub_id = t.pub_id;

这将生成一个第一列为NULL、后两列为空的表。

wlzqhblo

wlzqhblo1#

@JJ32给出了答案。我在比较两个不同的栏目。以下是工作代码:

SELECT t.title_id, t.title_name, p.pub_name,
    (SELECT CONCAT(a.au_fname, ' ', a.au_lname)
        from authors a
        JOIN title_authors ta ON a.au_id = ta.au_id
        WHERE ta.au_order = 1 and ta.title_id = t.title_id) as author_1,
    IFNULL((
        SELECT CONCAT(a.au_fname, a.au_lname)
        from authors a
        JOIN title_authors ta ON a.au_id = ta.au_id
        WHERE ta.au_order = 2 and ta.title_id = t.title_id),'') as author_2,
    IFNULL((
        SELECT CONCAT(a.au_fname, a.au_lname)
        from authors a
        JOIN title_authors ta ON a.au_id = ta.au_id
        WHERE ta.au_order = 3 and ta.title_id = t.title_id),'') as author_3
FROM titles t
JOIN publishers p
ON p.pub_id = t.pub_id;

相关问题