-1

我想要:

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

帮我显示结果

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,我已将您的代码更改为:

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

我试图引用一个现有但仍然存在的错误......

4

1 回答 1

0

我想要:

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

你的意思是你想qty_out成为 0 而不管它的原始值是多少?

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
于 2012-10-22T09:44:34.057 回答