Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
必须从我的postgresql查询中找到行数_Postgresql - Fatal编程技术网

必须从我的postgresql查询中找到行数

必须从我的postgresql查询中找到行数,postgresql,Postgresql,嗨,我试图从下面的查询中获取行数: select count(substring(wsresult_question FROM '[0-9]+') as pumporder) AS totals, job_id, job_siteid, job_completed from webserviceresults w, jobs s where job_sitei

嗨,我试图从下面的查询中获取行数:

        select count(substring(wsresult_question FROM '[0-9]+') as pumporder) AS totals,
            job_id,
            job_siteid,
            job_completed
            from webserviceresults w, jobs s 
            where job_siteid = '1401' 
            and job_id = wsresult_jobid
            and job_completed is not null
            and wsresult_question LIKE 'job.job_site_data.site_meters.pump.%' 
            and wsresult_category = 'Job' 
            group by pumporder,job_id,job_siteid,job_completed order by job_completed desc
我试过了,我得到了这样的错误

There was an SQL error: 
ERROR: syntax error at or near "as" LINE 1: ... count(substring(wsresult_question FROM '[0-9]+') as pumpord... ^
在这行
子字符串(wsresult_question FROM'[0-9]+')中,作为pumporder
我只想从一些串联字符串中获取一个数字。连接字符串如下所示

1.job.job\u site\u data.site\u meters.pump.0.meter\u calibration\u record.meter\u adjusted of ast

2.job.job\u site\u data.site\u meters.pump.0.meter\u calibration\u record.meter\u adjusted tolow

3.job.job\u site\u data.site\u meters.pump.1.meter\u calibration\u record.meter\u adjusted of ast

因此,
substring(wsresult_question FROM'[0-9]+')作为pumporder
返回数组中类似于0,1的数字。我现在需要合计行数。所以,请在这方面帮助我

如果您有任何疑问,请告诉我


提前谢谢

您的错误意味着您不应该为函数创建别名-仅为列创建别名,因此如果您将
作为pumporder
计数(子字符串(来自“[0-9]+”)作为pumporder)
中删除,错误将消失

不过你的方法很可疑。如果要使用
子字符串(wsresult\u问题来自“[0-9]+”)
计算行数,最好:

    select count(1) AS totals,
        job_id,
        job_siteid,
        job_completed
        from webserviceresults w, jobs s 
        where job_siteid = '1401' 
        and job_id = wsresult_jobid
        and job_completed is not null
        and wsresult_question  ~ '^(job.job_site_data.site_meters.pump.)[0-9]' 
        and wsresult_category = 'Job' 
        group by pumporder,job_id,job_siteid,job_completed order by job_completed desc
最后一个字符串
job.job\u site\u data.site\u meters.pump.0
看起来像json路径,因此使用json数组长度函数更合适,而不是计算行数