0

ここでの最初の質問の後、正しくテストされた以下のコードが表示されました。

SELECT DISTINCT
id, title, description, expires,
creator_id,executer_id,
oc_opentask.priority_id,
oc_opentask.status_id, priority_name, status_name,
oc_user1.username AS executer_username,
oc_user2.username AS creator_username
FROM oc_opentask
INNER JOIN oc_opentask_priority 
ON oc_opentask.priority_id=oc_opentask_priority.priority_id
INNER JOIN oc_opentask_status 
ON oc_opentask.status_id=oc_opentask_status.status_id
INNER JOIN oc_user AS oc_user1 
ON oc_opentask.executer_id=oc_user1.user_id
INNER JOIN oc_user AS oc_user2 
ON oc_opentask.creator_id=oc_user2.user_id

私の次の質問は次のとおりです。それらにアクセスし、WHERE属性を使用して値と比較したいexecuter_usernameのでcreator_username、私が試しているのは次のとおりです。

SELECT DISTINCT
id, title, description, expires,
creator_id,executer_id,
oc_opentask.priority_id,
oc_opentask.status_id, priority_name, status_name,
oc_user1.username AS executer_username,
oc_user2.username AS creator_username
FROM oc_opentask
INNER JOIN oc_opentask_priority 
ON oc_opentask.priority_id=oc_opentask_priority.priority_id
INNER JOIN oc_opentask_status 
ON oc_opentask.status_id=oc_opentask_status.status_id
INNER JOIN oc_user AS oc_user1 
ON oc_opentask.executer_id=oc_user1.user_id
INNER JOIN oc_user AS oc_user2 
ON oc_opentask.creator_id=oc_user2.user_id
WHERE oc_opentask.creator_username='bill' 

ビルはdbに存在しますが、その値にアクセスするための私のコマンドは正しくありません、any1はこれで私を助けることができますか?ありがとう

4

3 に答える 3

1

列エイリアスがあります:

oc_user2.username AS creator_username

そして、あなたのwhere句では、エイリアスを使用しています。実際の列名を使用する必要があるため、次のように変更します。

where oc_user2.username = 'bill'
于 2012-11-06T16:15:15.627 に答える
0

where句で作成者名を取得するために間違ったテーブルを使用しています。テーブルを使用oc_user2してユーザー名(作成者名)を取得します。また、私はまだ関連する問題があるかもしれないと思っているので、比較する前に、そして以下のように関数caseを使用することをお勧めします:LOWER

    SELECT DISTINCT
       id, title, description, expires,
       creator_id,executer_id,
       oc_opentask.priority_id,
       oc_opentask.status_id, priority_name, status_name,
       oc_user1.username AS executer_username,
       oc_user2.username AS creator_username
    FROM oc_opentask
    INNER JOIN oc_opentask_priority 
       ON oc_opentask.priority_id=oc_opentask_priority.priority_id
    INNER JOIN oc_opentask_status 
       ON oc_opentask.status_id=oc_opentask_status.status_id
    INNER JOIN oc_user AS oc_user1 
       ON oc_opentask.executer_id=oc_user1.user_id
    INNER JOIN oc_user AS oc_user2 
       ON oc_opentask.creator_id=oc_user2.user_id
    WHERE LOWER(oc_user2.username)=LOWER('bill')

LOWERケースに関係なく、ケースに依存しないように右側を使用していany valid nameます。

于 2012-11-06T16:15:51.543 に答える
0

これがMySQLの場合、WHEREの代わりにHAVINGを使用します。そうすれば、元の列名を指定したか、定義したエイリアスを指定したかに関係なく、問題が発生することはありません。HAVINGでは、集計関数の結果、つまりHAVING MAX(salary)> 40を使用することもできますが、WHEREも失敗します。

于 2014-01-20T02:59:24.587 に答える