mysql,sql查询问题,谢谢解答

1.SELECT MTAUT_ID,MTAUT_PARID FROM MT005AUT WHERE MTAUT_ID = 'MT10011'

2.SELECT MTAUT_ID,MTAUT_PARID,MTAUT_NAME,MTAUT_ADDRESS FROM MT005AUT WHERE MTAUT_PARID LIKE 'MT10000,MT10011%'

第1次查询是想获取MTAUT_PARID,然后在通过MTAUT_PARID去查询和这个值相关的数据,如何能把这两个语句并成一条语句写呢?谢谢解答

可能是我表述有问题,你们看到那个百分号没?

9个回答

 SELECT MTAUT_ID,MTAUT_PARID,MTAUT_NAME,MTAUT_ADDRESS FROM MT005AUT WHERE  MTAUT_PARID = (SELECT MTAUT_ID,MTAUT_PARID FROM MT005AUT WHERE MTAUT_ID = 'MT10011') and MTAUT_PARID LIKE 'MT10000,MT10011%'

SELECT MTAUT_ID,MTAUT_PARID,MTAUT_NAME,MTAUT_ADDRESS FROM MT005AUT WHERE MTAUT_PARID IN (SELECT MTAUT_PARID FROM MT005AUT WHERE MTAUT_ID = 'MT10011')

SELECT a.MTAUT_ID,a.MTAUT_PARID,a.MTAUT_NAME,a.MTAUT_ADDRESS FROM MT005AUT a,MT005AUT b WHERE 
a.MTAUT_PARID =b.MTAUT_PARID  and b.MTAUT_ID ='MT10011''

把第一条语句写成function

SELECT T.MTAUT_ID,T.MTAUT_PARID,T.MTAUT_NAME,T.MTAUT_ADDRESS FROM MT005AUT T WHERE T.MTAUT_PARID IN (SELECT MTAUT_PARID FROM MT005AUT T1 WHERE T.MTAUT_ID = 'MT10011')

SELECT MTAUT_ID,MTAUT_PARID,MTAUT_NAME,MTAUT_ADDRESS FROM MT005AUT WHERE MTAUT_PARID IN (SELECT MTAUT_PARID FROM MT005AUT WHERE MTAUT_ID = 'MT10011')

SELECT MTAUT_ID,MTAUT_PARID,MTAUT_NAME,MTAUT_ADDRESS FROM MT005AUT WHERE MTAUT_PARID IN (SELECT MTAUT_PARID FROM MT005AUT WHERE MTAUT_ID = 'MT10011')

SELECT MTAUT_ID,MTAUT_PARID,MTAUT_NAME,MTAUT_ADDRESS FROM MT005AUT WHERE MTAUT_PARID = (SELECT MTAUT_PARID FROM MT005AUT WHERE MTAUT_ID = 'MT10011') and MTAUT_PARID LIKE 'MT10000,MT10011%'

SELECT a.MTAUT_ID,a.MTAUT_PARID,a.MTAUT_NAME,a.MTAUT_ADDRESS FROM MT005AUT a,MT005AUT b WHERE
a.MTAUT_PARID =b.MTAUT_PARID and b.MTAUT_ID ='MT10011''

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问