select into 赋值:
select 0 into @starttime
select @starttime from DUAL
into后边应该还有个变量名,into前面也还要带上筛选字段,例如
select count(*) into v_count from dual;
这条语句的意思是查询dual表的所有记录数,将查询结果存入v_count变量中,也就是给变量设值的用法
可以给变量赋值
CREATE PROCEDURE cp_p_recived ()
BEGIN
SELECT
IFNULL(MAX(recived_time), 0) INTO @starttime
FROM
p_recived_before;
DELETE FROM p_recived_before;
INSERT INTO p_recived_before (
user_id,
recived_time,
recived_count,
create_time,
city_id
) SELECT
cp.user_id,
cp.recived_time,
cp.recived_count,
cp.create_time,
cp.city_id
FROM
(
SELECT
(
SELECT
user_id
FROM
addrdb.w_contacts
WHERE
phone = w.receiver_mobile
LIMIT 1
) AS user_id,
w.sign_date AS recived_time,
1 AS recived_count,
unix_timestamp(now()) * 1000 AS create_time,
receiver_city_id AS city_id
FROM
tmsdb.w_waybill w
WHERE
w.sign_date > @starttime
AND w. STATUS = 200
ORDER BY
w.sign_date ASC
LIMIT 2000
) cp;
SELECT IFNULL(MAX(recived_time), 0) INTO @mymaxtime FROM p_recived_before;
INSERT INTO p_recived (
user_id,
recived_time,
recived_count,
create_time,
city_id
) SELECT
pr.user_id,
pr.recived_time,
pr.recived_count,
pr.create_time,
pr.city_id
FROM
(
SELECT
user_id,
recived_time,
recived_count,
create_time,
city_id,
MAX(recived_time)
FROM
p_recived_before WHERE user_id is NOT NULL
GROUP BY
user_id
) pr
LEFT JOIN (
SELECT
user_id
FROM
p_recived
WHERE
create_time >= UNIX_TIMESTAMP(CAST(SYSDATE() AS DATE)) * 1000
AND create_time < UNIX_TIMESTAMP(CAST(SYSDATE() AS DATE) + 1) * 1000
) p ON pr.user_id = p.user_id
WHERE
pr.user_id > 0
AND pr.city_id > 0
AND p.user_id IS NULL;
DELETE
FROM
p_recived_before;
INSERT INTO p_recived_before (
recived_time
) VALUES (@mymaxtime);
END
13611227650
select * from tmsdb.w_waybill w where receiver_id='KH1710260000080'