简体   繁体   中英

div column in select MySQL query not working with replace into

I have some code like this:

REPLACE INTO digisob_rekap_peruser(
    user_rk,
    lokasi_lk,
    target_lk,
    pertarget //2. data does not enter this column ,
    vis_lk,
    nsb_lk)
SELECT
    jadwal_userid,
    lokasi_lk,
    target_kunjungan*$x,
    vis_lk/target_lk*100 AS pertarge //1. this line,
    COUNT(jadwal_userid) AS total,
    SUM(SJ_Tsel_3_2) AS jualan
FROM
    jadwal,
    data_kunjungan,
    user,
    digisob_rekap_peruser
WHERE

Number 1 has a result but this result does not enter the column in number 2.

The default data types for your percentage calculation is likley causing the data loss.

You need to cast the values to decimals/floats/doubles etc to handle it.

select 1/10
-- 0
select 1/10 * 100
-- 0
select cast(1 as decimal)/cast(10 as decimal)
-- 0.1000000000000000000
select cast(1 as decimal)/cast(10 as decimal) * 100
-- 10.0000000000000000
select cast(cast(1 as decimal)/cast(10 as decimal) * 100 as int)
-- 10
select cast(cast(cast(1 as decimal)/cast(10 as decimal) * 100 as int) as varchar(4)) + '%'
-- 10%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM