gpt4 book ai didi

MySql加入多选子查询

转载 作者:太空宇宙 更新时间:2023-11-03 11:37:39 24 4
gpt4 key购买 nike

-解决方案-

SELECT Table1.unvan, Table2.sayi FROM 
(SELECT id , unvan FROM unvan WHERE id IN
(SELECT unvani FROM personel WHERE gorev_yeri IN
(SELECT id FROM gorev_yeri WHERE il_id="34") ) ) AS Table1
JOIN
( SELECT unvani as id , count(*) AS sayi FROM personel WHERE gorev_yeri IN (SELECT id FROM gorev_yeri WHERE il_id="34") GROUP BY unvani ) AS Table2
ON Table1.id = Table2.id

-编辑-

当我使用 join with as 时出现此错误:#1064 - 你的 SQL 语法有错误;查看与您的 MySQL 服务器版本对应的手册,了解在 'AS table1

附近使用的正确语法

我有 2 个查询,我想加入它们。

It is first.

SELECT id
, unvan
FROM unvan
WHERE id IN (SELECT unvani
FROM personel
WHERE gorev_yeri IN (SELECT id
FROM gorev_yeri
WHERE il_id="34")
)

It is second one.

SELECT unvani as id
, count(*) AS sayi
FROM personel
WHERE gorev_yeri IN (SELECT id
FROM gorev_yeri
WHERE il_id="34") GROUP BY unvani

我需要这个:

乌凡|萨伊

--------|----

最佳答案

基于提供的错误

应该是这样的:

SELECT `Table1`.unvan, `Table2`.id
FROM
(
SELECT id
, unvan
FROM unvan
WHERE id IN (SELECT unvani
FROM personel
WHERE gorev_yeri IN (SELECT id
FROM gorev_yeri
WHERE il_id="34")
)
) AS `Table1`

JOIN

(
SELECT unvani as id
, count(*) AS sayi
FROM personel
WHERE gorev_yeri IN (SELECT id
FROM gorev_yeri
WHERE il_id="34") GROUP BY unvani
) AS `Table2`

ON `Table1`.id = `Table2`.id

关于MySql加入多选子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44411184/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com