2017-08-14 105 views
-4

不能執行該代碼...SQL GROUP BY和WHERE子句中PERL

use strict; 
use warnings; 

my $qstr = "select id as 'id', 
        status as 'status', 
        $subject.title as 'title', 
        $subject.component as 'component', 
        $subject.submitted_date as 'submitted_date', 
        $subject.closed_date as 'closed_date' 
      where ($subject.title like 'PM_Production' 
       and ($subject.status = 'complete' 
       OR $subject.status = 'rejected'))"; 
my $results = &search($api, $tenant, $subject, $qstr); 

foreach my $singleRow (@$results) { 
    my $title =$singleRow->{'title'}; 
    my $component = $singleRow->{'component'}; 
    my $sub_date = $singleRow->{'submitted_date'}; 
    my $closed_date = $singleRow->{'closed_date'}; 

    print "$title, $component, $sub_date, $closed_date\n"; 
} 

有如下的錯誤;

Syntax Error 

-- Error 15: Invalid Operator Found: "like" 

預期輸出:想過濾所有在標題中包含「PM_Pro」

P.S.數據數據標題示例:

Title    Ticket Submitted_date  Ticket closed_date 
PM_Pro_test1  2017-05-11 12:47:08.2  2017-05-26 07:00:16.0 
PM_Pro_test2  2017-05-11 13:23:10.96  2017-05-27 22:01:02.0 
Testi_PM_Pro  2017-05-11 13:23:02.483 2017-05-24 08:10:20.0 
Testii_PM_Pro  2017-05-11 13:28:35.247 2017-05-24 08:12:33.0 
+2

我承認這個代碼的東西。這不是真的SQL。你應該在這裏使用而不是'like'是'CONTAINS'' – Nullman

+2

這是無效的'SQL'。你沒有說明你想從哪個表中選擇。而且你不顯示你如何連接到數據庫服務器。您沒有詳細說明您嘗試連接的數據庫類型。沒有更多細節,可能沒有好的答案。 – dgw

回答

2

首先,您的列別名應該用雙引號引起來,或者不加引號。

其次,有沒有FROM子句(類似 「FROM $主題」)。

第三,看起來你需要=操盤手等。

看起來像你想寫像

my $qstr = "select $subject.id as id, $subject.status as status, $subject.title as title, $subject.component as component, $subject.submitted_date as submitted_date, $subject.closed_date as closed_date from $subject where ($subject.title = 'PM_Production' and ($subject.status = 'complete' OR $subject.status = 'rejected'))";