标题:用in做的子查询返回1200行的时候前面主句就会报错子查询不止一个,但返回10 ...
只看楼主
su13800
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-8-16
结帖率:0
已结贴  问题点数:20 回复次数:4 
用in做的子查询返回1200行的时候前面主句就会报错子查询不止一个,但返回1050行的时候是正常的。
SELECT
    tb_publicvoice.*, (
        SELECT
            did
        FROM
            tb_daily_pv
        WHERE
            tb_daily_pv.pvid = tb_publicvoice.id

    ) AS daily_id,
    (
        SELECT
            (
                SELECT
                    CAST (dispose_doc_no AS VARCHAR) + ','
                FROM
                    tb_pv_dispose
                WHERE
                    tb_pv_dispose.id

 = tb_publicvoice.id

 FOR xml path ('')
            )
    ) AS dispose_doc_no,
    (
        SELECT
            daily_id
        FROM
            tb_pv_feedback_daily
        WHERE
            tb_pv_feedback_daily.id

 = tb_publicvoice.id

    ) AS feedback_daily_id,
    (
        SELECT
            COUNT (*)
        FROM
            tb_pv_comment
        WHERE
            tb_pv_comment.id

 = tb_publicvoice.id

    ) AS comment_count,
    (
        SELECT
            content
        FROM
            tb_pv_feedback
        WHERE
            tb_pv_feedback.id

 = tb_publicvoice.id

        AND tb_pv_feedback.type = 0
    ) AS docFeedback,
    (
        SELECT
            content
        FROM
            tb_pv_feedback
        WHERE
            tb_pv_feedback.id

 = tb_publicvoice.id

        AND tb_pv_feedback.type = 1
    ) AS webFeedback
FROM
    tb_publicvoice
WHERE
    tb_publicvoice.id

 IN (
        SELECT
            pvid
        FROM
            tb_pv_notify
        WHERE
            tb_pv_notify.uid = 'admin'
    )
AND tb_publicvoice.createtime < '2017-08-16'
AND tb_publicvoice.createtime > '2016-08-16'
ORDER BY
    tb_publicvoice.createtime DESC
搜索更多相关主题的帖子: 子查询 返回 SELECT FROM WHERE 
2017-08-16 10:11
su13800
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-8-16
得分:0 
大神在哪里出来指教下。
2017-08-16 10:13
mywisdom88
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:10 
看了下,好像没什么问题.
SELECT
 tb_publicvoice.*,
 ( SELECT did FROM tb_daily_pv WHERE tb_daily_pv.pvid = tb_publicvoice.id ) AS daily_id,
 ( SELECT ( SELECT CAST (dispose_doc_no AS VARCHAR) + ',' FROM tb_pv_dispose WHERE tb_pv_dispose.id = tb_publicvoice.id  FOR xml path ('')) ) AS dispose_doc_no,
 ( SELECT daily_id FROM  tb_pv_feedback_daily WHERE tb_pv_feedback_daily.id  = tb_publicvoice.id ) AS feedback_daily_id,
 ( SELECT COUNT (*) FROM tb_pv_comment WHERE  tb_pv_comment.id = tb_publicvoice.id ) AS comment_count,
 ( SELECT content FROM tb_pv_feedback WHERE tb_pv_feedback.id = tb_publicvoice.id AND tb_pv_feedback.type = 0) AS docFeedback,
 ( SELECT content FROM tb_pv_feedback WHERE tb_pv_feedback.id = tb_publicvoice.id AND tb_pv_feedback.type = 1) AS webFeedback

 FROM tb_publicvoice
 WHERE
  tb_publicvoice.id  IN ( SELECT pvid FROM tb_pv_notify WHERE tb_pv_notify.uid = 'admin' )
  AND tb_publicvoice.createtime < '2017-08-16'
  AND tb_publicvoice.createtime > '2016-08-16'
 ORDER BY tb_publicvoice.createtime DESC

2017-08-16 14:42
mywisdom88
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:0 
有可能出现问题的,可以在这
( SELECT ( SELECT CAST (dispose_doc_no AS VARCHAR) + ',' FROM tb_pv_dispose WHERE tb_pv_dispose.id = tb_publicvoice.id  FOR xml path ('')) ) AS dispose_doc_no,
你把这个先去掉看看.
2017-08-16 14:47
mingfei
Rank: 2
等 级:论坛游民
帖 子:3
专家分:30
注 册:2017-8-21
得分:10 
我感觉 可能是有数据问题
2017-08-21 17:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-480080-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.324788 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved