سؤال

I want to:

if the value qty_out! = 0, then set qty_out = 0

Help me to display results

SELECT
    SUBSTR(stok_control.tgl_faktur,9,2) AS 'tanggal',
    SUBSTR(stok_control.tgl_faktur,6,2) AS 'bulan',
    CONCAT(
        (SELECT(
            IFNULL(stok_control.faktur_beli,''))
        )       
        ,
        (SELECT(
            IFNULL(stok_control.faktur_jual,''))
        )
    ) AS 'faktur',
    bahan.id AS 'kode_bahan',
    bahan.nm_bahan AS 'nama_bahan',

    stok_control.qty_in AS 'masuk',
    (
    SELECT IF(stok_control.qty_out != '',0,0) 
    FROM 
        stok_control
    WHERE 
        stok_control.faktur_beli !=''
    ) AS 'keluar'

FROM
    stok_control 
LEFT JOIN bahan ON stok_control.id_bahan=bahan.id

@eggyal, I have changed your code to be:

SELECT 
    SUBSTR(sc.tgl_faktur, 9, 2) AS 'tanggal',
    SUBSTR(sc.tgl_faktur, 6, 2) AS 'bulan',
    CONCAT(
        IFNULL(sc.faktur_beli, ''),
        IFNULL(sc.faktur_jual, '')
        ) AS 'faktur',
    b.id        AS 'kode_bahan',
    b.nm_bahan  AS 'nama_bahan',
    (SELECT IFNULL(sc.qty_in,0))  AS 'masuk',
    (SELECT
        (
            IF(faktur_beli <> '',
                0,
                (SELECT sc.qty_out)
            ) 
        )

    ) AS 'qty_out'
FROM   
    stok_control sc LEFT JOIN bahan b ON sc.id_bahan = b.id

I've tried to reference an existing but still error...

هل كانت مفيدة؟

المحلول

I want to:

if the value qty_out! = 0, then set qty_out = 0

Do you mean that you want qty_out to be 0 irrespective of its original value?

SELECT SUBSTR(sc.tgl_faktur, 9, 2) AS tanggal,
       SUBSTR(sc.tgl_faktur, 6, 2) AS bulan,
       CONCAT(
         IFNULL(sc.faktur_beli, ''),
         IFNULL(sc.faktur_jual, '')
       )                           AS faktur,
       b.id                        AS kode_bahan,
       b.nm_bahan                  AS nama_bahan,
       sc.qty_in                   AS masuk,
       0                           AS qty_out
FROM   stok_control sc LEFT JOIN bahan b ON sc.id_bahan = b.id
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top