SQL常用指令

xiaoxiao2021-02-27  376

一、Android插入方式: 1.、 mSQLiteDatabase.execSQL(insertSQL); 如果insertSQL里面有双引号单引号这些特殊字符会插入失败 2. mSQLiteDatabase.execSQL(insertSQL,mValue); 这种方式不会因为特殊字符而插入失败

String insertSQL = "insert into questionbank(id,category_id,interview_id,question," + "optiona,optionb,optionc,optiond,anwser,mexplain,type,url,link_ids) values(?,?,?,?,?,?,?,?,?,?,?,?,?)"; String[] mValue=new String[]{ null, dataBean.getCategoryId(), dataBean.getInterviewId(), dataBean.getQuestion(), dataBean.getAnswerA(), dataBean.getAnswerB(), dataBean.getAnswerC(), dataBean.getAnswerD(), dataBean.getAnswer(), dataBean.getExplain(), dataBean.getType(), dataBean.getUrl(), dataBean.getLinkIds()}; // String insertSQL="insert into questionbank values(null," + // "'"+dataBean.getCategoryId()+ "'," + // "'"+dataBean.getInterviewId()+"'," + // "'"+dataBean.getQuestion()+"'," + // "'"+dataBean.getAnswerA()+"'," + // "'"+dataBean.getAnswerB()+"'," + // "'"+dataBean.getAnswerC()+"'," + // "'"+dataBean.getAnswerD()+"'," + // "'"+dataBean.getAnswer()+"'," + // "'"+dataBean.getExplain()+"'," + // "'"+dataBean.getType()+"'," + // "'"+dataBean.getUrl()+"'," + // "'"+dataBean.getLinkIds()+"')"; // mSQLiteDatabase.execSQL(insertSQL); mSQLiteDatabase.execSQL(insertSQL,mValue);

没有记录则插入

INSERT INTO questionbank ( category_id, interview_id, question, optiona, optionb, optionc, optiond, anwser, type, url, link_ids ) SELECT 'c1', 'interview100090', '什么是狐狸', 'AAA', 'BBB', 'CCC', 'DDD', 'DDD', '1', 'http', 'u1000' WHERE NOT EXISTS(SELECT * FROM questionbank WHERE interview_id='interview1000901')

没有记录则插入,有责更新操作

INSERT INTO tea_store_user(store_id,user_id,point) VALUES('2','1',1) ON DUPLICATE KEY UPDATE point=point+1;

根据cust_baseinfo表的cityid查询branch_baseinfo表的所以信息

SELECT * FROM branch_baseinfo bb WHERE bb.cityid IN( SELECT cb.cityid FROM cust_baseinfo cb WHERE custid='b148245802216443' )

根据查询结果更新

UPDATE lianjiub_secondactivity ls SET ls.second_count = ls.second_count+1 WHERE ls.said = ( SELECT l.said FROM lianjiub_secondorder l WHERE l.requestid='po514963794722969703')
转载请注明原文地址: https://www.6miu.com/read-2563.html

最新回复(0)