如果像这样查询,如何生成结果 kondisi
查询结果需要这样,但是条件使用
IIF
不+Induk | 果酱_In | 康迪西 |
---|---|---|
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 00:00 | 0 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 00:00 | 0 |
xx123 | 08:00 | 37500 |
xx123 | 07:00 | 0 |
xx123 | 07:06 | 22500 |
xx123 | 07:10 | 22500 |
xx123 | 07:15 | 22500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 00:00 | 0 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
xx123 | 00:00 | 0 |
xx123 | 08:00 | 37500 |
xx123 | 08:00 | 37500 |
DECLARE @kondisi INT;
SELECT
@kondisi = IIF(jam_in >= '07:06' AND jam_in < '07:20', (75000 * 30 / 100),
IIF(jam_in >= '07:20' AND jam_in < '08:56', (75000 * 50 / 100),
IIF(jam_in >= '15:06' AND jam_in < '15:20', (75000 * 30 / 100),
IIF(jam_in >= '15:21' AND jam_in < '15:31', (75000 * 30 / 100), 0))))
FROM tblabsen
WHERE no_induk = 'xx123';
-- Debugging output
SELECT no_induk, jam_in, @kondisi AS kondisi
FROM tblabsen
WHERE no_induk = 'xx123';
我绝对不会使用类似IIF()
之类的东西。您可以采用多种不同的方法来代替,但我最近一直在做的是将您的
jamin
=> 公式映射定义为data 我可以加入到表值构造函数中
SELECT no_induk, jam_in, (75000 * m.Multiplier) / 100 as kondisi
FROM tblabsen a
INNER JOIN (VALUES
('07:06', '07:20', 30),
('07:20', '08:56', 50),
('15:06', '15:20', 30),
('15:21', '15:31', 30)
) m(MinTime, MaxTax, Multiplier) ON a.jam_in >= m.MinTime AND a.jam_in < m.MaxTime
WHERE no_induk = 'xx123' AND priode = '112016';