我只是想问一下,当我的一个查询返回t时,是否可以触发查询?这是我的示例代码
WITH tbl AS (select x.id, x.quantity , IIF(z.Status = 'Hired', 1,0) AS Hired
FROM open_ijo x
LEFT JOIN applicants_detail y ON y.ijoID=x.id
LEFT JOIN career_status z ON z.id=y.status
WHERE y.ijoid=x.id
AND y.status<>'8'
AND z.status<>'Open'
AND z.status <> 'withdrawn'
AND ijodateposted IS NOT NULL)
SELECT id, quantity, SUM(hired) AS hired
FROM tbl
GROUP BY id, quantity
输出结果为:
id quantity hired
61 6 1
62 1 1
63 1 0
我想要实现的是,当数量仍不等于雇用时,它将显示此查询:
SELECT x.id, x.applicanteid, x.roleapplied, y.id AS ijoid,
x.dateapplied, z.status, a.careerlevel, IIF(z.Status = 'Hired', 1,0) AS Hired
FROM applicants_detail x
LEFT JOIN open_ijo y ON y.id=x.ijoid
LEFT JOIN career_status z ON z.id=x.status
LEFT JOIN roster a ON a.eid=x.applicantEID
WHERE y.id=x.ijoid and x.applicanteid IS NOT NULL
AND z.status <> 'Open' AND
ijodateposted IS NOT NULL AND z.status <> 'Withdrawn'
AND x.status <> '8'
当数量达到受雇人数时,会显示一个无法显示的文字。
答案 0 :(得分:2)
可以使用IF...ELSE
IF EXISTS (QUERY1)
QUERY2
答案 1 :(得分:0)
是的,您可以使用IF .. ELSE
构造,但这只能在BEGIN .. END
块内的过程代码中(即在存储过程或存储函数内...)。
但是如果你想要内联访问其他查询值,那么你可以将该查询包装为子查询,然后可以在外部查询中访问内部/子查询中的所有列...但是看起来这不是你想要的。