开发者

select SQL query

开发者 https://www.devze.com 2023-02-05 17:55 出处:网络
I have a three tables table 1 - key columns p1,p2 ta开发者_运维技巧ble 2 - key columnsp1, STATUS

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

精彩评论

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