SELECT TD.CUSTOMER_NO,TD.CARE_MONTH
FROM table
WHERE
CUSTOMER_NO = '1' AND CARE_MONTH = '20120821'
SQL code
INSERT INTO
table(CUSTOMER_NO,CARE_MONTH,REGISTER,REGIST_TIME,UPDATER,UPDATE_TIME)
VALUES('1','20120821')
可否用一个SQL文 实现SELECT查不出来数据的话 就把这条数据查到数据库里
------解决方案-------------------- insert into table1(CUSTOMER_NO,CARE_MONTH) --列的数量一定要和插入的值个数一样 (select * from (select '1' id,'20120821' name ) a --这个是MSSQL中的写法 where not exists (SELECT 1 FROM table1 WHERE CUSTOMER_NO = '1' AND CARE_MONTH = '20120821') )
以上在MSSQL中测试是没问题的
------解决方案--------------------
------解决方案-------------------- 最好使用merge吧,效率比较高。
------解决方案-------------------- 是Oracle数据库还是mysql数据库呢?
------解决方案-------------------- merge into security_clutter a using (select '90001' ls_code,'PWD' act_code ,'test' act_name from dual ) b on (a.act_code = b.act_code) when matched then update set a.act_name = b.act_name when not matched then insert values (b.ls_code, b.act_code, b.act_name, '', '')
------解决方案-------------------- 楼上的when matched的应该可以跳过,直接when not matched...
------解决方案-------------------- merge 可以解决!