开发者

select SQL query

I have a three tables

table 1 - key columns p1, p2

ta开发者_运维技巧ble 2 - key columns p1, STATUS

table 3 - key columns p2, STATUS

In table 1, if p1 is 0, then p2 will have value. but not the vice versa. If p1 is there, then I need to check status in table 2, if not I need to check the status in table 3.

Now I need select find count of rows which are having pending status in any of table 2 and 3 from table 1.

Please help. thanks in advance


SELECT  CASE p1 WHEN 0 THEN t2.status ELSE t3.status END
FROM    t1
LEFT JOIN
        t2
ON      t2.p1 = p1
LEFT JOIN
        t3
ON      t1.p1 = 0
        AND t3.p2 = t1.p2
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜