select查询中嵌套update操作,可有人能用一条SQL实现?

select * from 表 where id = 1;
update 表 set reading = reading =1 where id = 1;
这两条SQL是在一张表中,我要先进行update操作,然后再进行查询操作。

sql

2个回答

update table_name set reading = (select reading from table_name t where t.id = 1);

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Python+OpenCV计算机视觉

Python+OpenCV计算机视觉

sql update set select 怎么结合

如何实现 update BAS_COMPANY set TYPE ='5' where COMNO = (select * from hbposev9..t_bd_supcust_info where supcust_flag ='C') 更新里 含查询 更新BAS_COMPANY表内TYPE列为5 条件是另外 hbposev9..t_bd_sup表里 supcust_flag为C

MySQL中用于根据另一个字段的最大值更新字段的嵌套select语句会产生错误

<div class="post-text" itemprop="text"> <p>I want to execute the following SQL statement in PhP. I have simplified it below. I would like to know the MySQL modifications to make it work. I tried a few like giving aliases to the tables but it did not work:</p> <pre><code> update T1 set col1 = 500 where col2 = 12345 and col3 = (select max(col3) from T1 where col2 = 12345) </code></pre> <p>I want to update a record which has the max value for one column. There is only one table involved in the entire query. I am using PDO, if that is relevant.</p> <p>The error given is:</p> <pre><code>#1093 - You can't specify target table 'T1' for update in FROM clause </code></pre> </div>

mysql存储过程中的多个select问题

在存储过程中有多个select,但我想只让最后那个select作为结果集返回,怎么屏蔽其他的select输出?

Mybatis select 没有获取更新数据 (缓存 ?)

写了一个简单的mybatis demo,没有集成其他事务管理,对接mysql数据库。 在表file_resources的mapper里面定义了一个这样的嵌套sql , 里面用到了 postinfo 、 poststatus两个表 ``` </select> <select id="selectPendingPostItemCount" resultType="java.lang.Integer" flushCache="true" useCache="false"> select count(*) from file_resources where objectName in (SELECT PostID FROM postinfo where PostLink not in (select PostLink from poststatus) group by postid having count(1) = 1) </select> ``` 我有另外一个线程去跑一些处理,是做完一条就commit一条的,poststatus的数据会不断增多,这样上面sql获取的count是不断减少的,我在mysql workbench控制台跑这条sql,count是不断会减少的。 但是当我开一个新线程在程序里跑count那条sql时,发觉无法获取到更新的数据,只有第一次跑时返回正确的count,之后这个count都没有改变(但在mysql workbench控制台跑,是不断减少的) 最开始的版本是这样的,sqlsession是用单例获取重用的open session,一开始就取好mapper,然后慢慢循环去跑sql,无法获取到更新count。 ``` SqlSession refreshSession = SessionFactorySingleton.getInstance().getOpenSession(); FileResourcesMapper fileMapper = refreshSession.getMapper(FileResourcesMapper.class); while(true){ int count = fileMapper.selectPendingPostItemCount(); Thread.sleep(50000); } ``` 直觉怀疑是缓存的问题,谷哥度娘之,然后作了几点修改,问题依旧。 1: 没有用单例获取sqlsession,而是重新按SqlSessionFactoryBuilder方法获取新的open session,并每次重新取mapper去跑select,问题依旧。 2:每次run完selection之后跑clearCache() 跟commit,问题依旧。 3:修改mapper ,在selectPendingPostItemCount定义 flushCache跟useCache去控制一二级缓存,问题依旧。 ``` </select> <select id="selectPendingPostItemCount" resultType="java.lang.Integer" flushCache="true" useCache="false"> select count(*) from file_resources where objectName in (SELECT PostID FROM postinfo where PostLink not in (select PostLink from poststatus) group by postid having count(1) = 1) </select> ``` ``` // SqlSession refreshSession = SessionFactorySingleton.getInstance().getOpenSession(); SqlSession refreshSession = getNewOpenSession(); //get new open session from new SqlSessionFactoryBuilder FileResourcesMapper fileMapper = refreshSession.getMapper(FileResourcesMapper.class); while(true){ int count = fileMapper.selectPendingPostItemCount(); refreshSession.clearCache(); refreshSession.commit(); fileMapper = refreshSession.getMapper(ColafileResourcesMapper.class); Thread.sleep(50000); } ``` 这之后,我就去看了看缓存跟sql执行的代码。 CachingExecutor 里面MappedStatement取出来的cache都是null的 , BaseExecutor里面的clearLocalCache()也有被call起来 最后BaseExecutor也involve了SimpleExecutor的doQuery(),里面就是jdbc的基本操作,PreparedStatementHandler的execute方法去执行sql。已经与缓存没有什么关系。 但是返回的值就是旧的。。。。。 打开的debug log可以证实sql已经提交连接数据库,同时我也在后台看到了sql语句的执行,但是从程序那边读取的返回值就是死活没有更新到。(在后台mysql界面直接跑同一条sql是有更新的) 我们现在的方法是每次跑mapper的selectPendingPostItemCount() 方法之后,就去直接把连接关闭掉(refreshSession.close())。下一次查询时重新取过sqlsession去跑select,是可以的。 有这方便经验的童鞋知道是什么问题麽 ?或者 可以给点意见或方向给我们去排查一下,感激不尽。 现在在看是不是namespace的问题,就是里面嵌套了其他file,是postinfo 、 poststatus两个表被缓存了 ? ``` <mapper namespace="com.mybatis.inter.FileResourcesMapper" > <resultMap id="BaseResultMap" type="com.mybatis.model.FileResources" > <id column="objectLink" property="objectlink" jdbcType="VARCHAR" /> 。。。。。。 ```

向sql语句的动态变量传值

哪位大神知道怎么向这条sql语句的动态变量传值,select 4800 from piccl p where ?ProdID? in ('62483','62484') and ?ManageOrgan? in ('1130000','1150000','1220000','1330000','1370000','1410000','1530000')

关于Mybatis子查询嵌套问题

直接上Sql代码 ``` SELECT t.*, ( SELECT count( s.un_sid ) FROM un_star s WHERE t.un_pid = s.un_pid AND s.un_uid = #{unUid,jdbcType=INTEGER) ) AS 'skey', ( SELECT count( l.un_lid ) FROM un_like l WHERE t.un_pid = l.un_pid AND l.un_uid = #{unUid,jdbcType=INTEGER) ) AS 'lkey' FROM ( SELECT a.*, b.un_uname, b.un_uid, b.un_upic FROM `un_pic` a, `un_user` b WHERE b.un_uid = a.un_plinkid AND a.un_pstatus = 0 ORDER BY a.un_pid DESC ) t ``` 运行的话会报错如下图 ![图片说明](https://img-ask.csdn.net/upload/202002/26/1582726793_704770.jpg) 我把 ( SELECT count( s.un_sid ) FROM un_star s WHERE t.un_pid = s.un_pid AND s.un_uid = 3) AS 'skey', ( SELECT count( l.un_lid ) FROM un_like l WHERE t.un_pid = l.un_pid AND l.un_uid = 3) ) AS 'lkey' 这两句的 #{}里面 直接换成数字ID就可以正常通过,就很纳闷,怎么才能把UID传递进去呢? 目前的mybatis里是这样写的 ``` <select id="selectUserHomePic" resultMap="QueryPicList" parameterType="java.lang.Integer" > SELECT t.*, (SELECT count( s.un_sid ) FROM un_star s WHERE t.un_pid = s.un_pid AND s.un_uid = #{unUid,jdbcType=INTEGER)) AS 'skey', (SELECT count( l.un_lid ) FROM un_like l WHERE t.un_pid = l.un_pid AND l.un_uid = #{unUid,jdbcType=INTEGER)) AS 'lkey' FROM ( SELECT a.*, b.un_uname, b.un_uid, b.un_upic FROM `un_pic` a, `un_user` b WHERE b.un_uid = a.un_plinkid AND a.un_pstatus = 0 ORDER BY a.un_pid DESC ) t </select> ``` 求助 已经解决了该问题了!请遇到此类 链接多个数据表,并且传递参数的时候,要将参数放在 最外层的where去 传递, 括号()里面的select语句传递参数是获取不到的 如下 ``` <select id="selectUserHomePic" resultMap="QueryPicList" parameterType="java.lang.Integer" > SELECT t.*, (SELECT count( s.un_sid ) FROM un_star s WHERE t.un_pid = s.un_pid AND s.un_uid = b.un_uid) AS 'skey', (SELECT count( l.un_lid ) FROM un_like l WHERE t.un_pid = l.un_pid AND l.un_uid = b.un_uid ) AS 'lkey' FROM ( SELECT a.*, b.un_uname, b.un_uid, b.un_upic FROM `un_pic` a, `un_user` b WHERE b.un_uid = a.un_plinkid AND a.un_pstatus = 0 ORDER BY a.un_pid DESC ) t , `un_user ` b where b.un_uid = #{unUid,jdbcType=INTEGER) </select> ``` 将()内的 #{unUid,jdbcType=INTEGER) 移植到下面去

PHP中的SQL语句错误,但SQL中的错误

<div class="post-text" itemprop="text"> <p>The following SQL statement runs correctly against a MySQL database table in an SQL script or in phpmyadmin but errors when run from within a PHP script.</p> <p>The SQL statement is:</p> <pre><code>update traceability t1 inner join traceability t2 on (t1.parent in (select t2.child)) set t1.root=false; </code></pre> <p>in the PHP script the code looks like:</p> <pre><code>$sqlupdatestmt = $db-&gt;query("update traceability t1 inner join traceability t2 on (t1.parent in (select t2.child)) set t1.root=false;"); $sqlupdatestmt-&gt;execute(); </code></pre> <p>The error in the PHP log is:</p> <pre><code>PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 't2.child' in 'field list'' in /&lt;myfilepath&gt; /traceability.php:50 Stack trace: #0 /&lt;myfilepath&gt;/traceability.php(50): PDO-&gt;query('update traceabi...') #1 {main} </code></pre> <p>What's going wrong in the PHP that it throws a PHP/SQL error?</p> <p>Here is information on traceability table schema:</p> <pre><code>Field Type Null Key Default Extra Variant varchar(20) YES MUL NULL Parent varchar(50) YES NULL Child varchar(50) YES NULL Relation varchar(20) YES NULL Root tinyint(1) YES NULL Leaf tinyint(1) YES NULL </code></pre> </div>

存储过程同时Update 多张表问题

如下存储过程写法对吗?执行成功,没有报错,但是实际查询数据时发现数据并没有被更新,求解答,问题出在哪里呢? create or replace procedure emp_role_disable Is Begin Update c_userxrole Set expiration_date=Sysdate+14,lm_user='autocim' ,lm_time =systimestamp Where upper(userid) In (Select emp_data.emp_no From emp_data Where trans_date Is Not Null); Update c_usr_user Set is_enable=0,is_quit=1 ,LM_USER='CIM',disable_date=Sysdate Where is_enable=1 And is_quit=0 And upper(userid) Not In (Select emp_data.emp_no From emp_data); end emp_role_disable; 说明,两个sql 拉出来直接在plsql上执行是Ok的 ------ 存储过程执行后,数据没有变化;然后我定义了一个job,周期执行这个存储过程。job执行成功,数据也更新了。。问题:存储过程不能手动执行吗?就是按F8执行,一定要其它触发执行?

为什么select min(id) 外面还要套一个select id in ?

![图片说明](https://img-ask.csdn.net/upload/201906/26/1561530114_447351.png) 为什么select min(id) 外面还要套一个select id in ?在select min id 中不是已经把符合要求的id都选出来了吗

如何在json中返回嵌套对象列表?

<div class="post-text" itemprop="text"> <p>I'm using <code>Slim</code> for write a little rest api, and I have the following situation: I need to return a list of competitions which have different seasons available, now if I do this:</p> <pre><code>$app-&gt;get('/get_competitions', function (Request $request, Response $response, array $args) { $sql = $this-&gt;db-&gt;query("SELECT * FROM competition INNER JOIN competition_seasons ON competition.id = competition_seasons.competition_id WHERE country_id IS NOT NULL"); $sql-&gt;execute(); $comps = $sql-&gt;fetchAll(); return $response-&gt;withJson($comps); }); </code></pre> <p>this will return the following response:</p> <pre><code>[ { "id": "1", "country_id": "1", "name": "2017", "link": "https:\/\/int.soccerway.com\/national\/afghanistan\/afghan-premier-league\/c1093\/", "competition_id": "1093", "season_id": "13198", "update_at": "2018-05-14 12:51:17" }, { "id": "2", "country_id": "1", "name": "2018", "link": "https:\/\/int.soccerway.com\/national\/afghanistan\/afghan-premier-league\/c1093\/", "competition_id": "1093", "season_id": "14963", "update_at": "2018-05-16 12:10:16" }, { "id": "5", "country_id": "1", "name": "2016", "link": "https:\/\/int.soccerway.com\/national\/afghanistan\/afghan-premier-league\/c1093\/", "competition_id": "1093", "season_id": "12091", "update_at": "2018-05-14 12:52:47" }, { "id": "6", "country_id": "1", "name": "2015", "link": "https:\/\/int.soccerway.com\/national\/afghanistan\/afghan-premier-league\/c1093\/", "competition_id": "1093", "season_id": "10891", "update_at": "2018-05-14 12:54:12" }, { "id": "7", "country_id": "1", "name": "2014", "link": "https:\/\/int.soccerway.com\/national\/afghanistan\/afghan-premier-league\/c1093\/", "competition_id": "1093", "season_id": "8868", "update_at": "2018-05-14 12:55:40" }, { "id": "8", "country_id": "1", "name": "2013", "link": "https:\/\/int.soccerway.com\/national\/afghanistan\/afghan-premier-league\/c1093\/", "competition_id": "1093", "season_id": "7851", "update_at": "2018-05-14 12:57:02" }, { "id": "9", "country_id": "1", "name": "2012", "link": "https:\/\/int.soccerway.com\/national\/afghanistan\/afghan-premier-league\/c1093\/", "competition_id": "1093", "season_id": "7816", "update_at": "2018-05-14 12:58:34" }, { "id": "10", "country_id": "2", "name": "2017\/2018", "link": "https:\/\/int.soccerway.com\/national\/albania\/super-league\/c48\/", "competition_id": "48", "season_id": "14214", "update_at": "2018-05-16 12:11:12" } ] </code></pre> <p>as you can see the competition available have the id <code>1093</code> and different seasons, how can I optimize the query (if is possible), to return a response which contains one competition with a list of seasons? </p> <p>Something like:</p> <pre><code>[ { "id":"1", "country_id":"1", "name":"2017", "link":"https:\/\/int.soccerway.com\/national\/afghanistan\/afghan-premier-league\/c1093\/", "competition_id":"1093", "seasons":[ "season_id":13198, "season_id":12091, etc.. ], "update_at":"2018-05-14 12:51:17" } ] </code></pre> <p>Thanks.</p> </div>

sql-error:too many values

select USER_ID,USER_GRD_ID from CUST_GRD where USER_ID in (select EUSER_ID, max(START_DATE) from CUST_GRD group by USER_ID) 我先把user_id group by 后挑选每个id中日期最大的那条 。再查询USER_ID,USER_GRD_ID 可是报错如上 请问各位大神是什么意思?

php mysql中的嵌套循环

<div class="post-text" itemprop="text"> <p>I cant update the corresponding edited items. Only the first questions and answers are being updated. I cant get the result that I want. Im stuck on this for a day. Please help me.</p> <p>Heres the scenario: I have a php file that contains the form and passes it to another php file. a checkbox that has the question id and textboxes that allows them to edit their questions from the database. Every question has its corresponding answers. Also, they can edit them. If they click update button all of the checked questions should be updated. but not all of them is updated. Literally only the first question is the only item that can be updated. Anyone knows whats wrong with my code??</p> <p>heres a link for the screenshot <a href="http://imageshack.us/photo/my-images/706/cetw.png/" rel="nofollow">http://imageshack.us/photo/my-images/706/cetw.png/</a></p> <p>Heres my code:</p> <pre><code>$selected = $_POST['selected'];///the checkbox $question = $_POST['questiondesc']; for ($i = 0; $i &lt; sizeof($selected); $i++) { $sql = sprintf("UPDATE exam_questions SET question_description = '%s' WHERE question_id = '%s'", mysql_real_escape_string($question[$i]), mysql_real_escape_string($selected[$i])); mysql_query($sql)or die(mysql_error()); $eren = mysql_query("SELECT * FROM exam_answers WHERE answer_question_set_id = '".$selected[$i]."'")or die(mysql_error()); while($mikasa = mysql_fetch_array($eren)){} $count = mysql_num_rows($eren); $answer = $_POST['answerdesc']; $answerid = $_POST['ansid'];///answer id for($e = 0; $e&lt;$count; $e++){ $gomugomu = sprintf("UPDATE exam_answers SET answer_description = '%s' WHERE answer_id = '%s'", mysql_real_escape_string($answer[$e]), mysql_real_escape_string($answerid[$e])); mysql_query($gomugomu)or die(mysql_error()); } </code></pre> </div>

Mysql在复杂查询中使用GROUP_CONCAT加入

<div class="post-text" itemprop="text"> <p>我遇到了一个运行查询的问题,我有三个表:</p> <p><strong>categories</strong></p> <pre><code>| id | name | | --- | ---------- | | 1 | Logo | | 2 | Poster | | 3 | Stationary | | 4 | Web | | 5 | Projects | | 6 | Sporadic | </code></pre> <p><strong>photos</strong> </p> <pre><code>| id | portid | image | preveiw | | --- | ------ | ---------------- | ------- | | 171 | 30 | a30preview.jpg | 1 | | 172 | 30 | b30.jpg | | | 173 | 30 | c30.jpg | | | 174 | 32 | a32preview.jpg | 1 | | 175 | 32 | b32.jpg | | | 176 | 33 | a33preview.jpg | 1 | | 179 | 33 | b33.jpg | | | 180 | 41 | a41preview.jpg | 1 | </code></pre> <p><strong>portfolios</strong></p> <pre><code>| id | catid | type | title | text | date | | --- | ------ | ----- | ------------ | ------------ | ------ | | 30 | 2 | M | xxxxxxxx | xxxxxxxx | xxxxxx | | 32 | 2 | M | xxxxxx | xxxxxx | xxxxxx | | 33 | 2 | L | xxxxxxxxxx | xxxxxxxxxx | xxxxxx | | 41 | 1 | L | xxxx | xxxx | xxxxxx | | 45 | 2 | L | xxxxx | xxxxx | xxxxxx | &lt;-(This record has no image in 'photos' table, so it's not in 'output') </code></pre> <p>我想把这些记录作为输出(其中name=‘post’):</p> <pre><code>| id | catid | name | type | title | text | date | image &lt;-(first image is the one that has 'photos.preview' = 1)| | --- | ------ | -------- | ----- | ------------ | ------------ | ------ | ---------------------------------- | | 30 | 2 | Poster | M | xxxxxxxx | xxxxxxxx | xxxxxx | a30preview.jpg, b30.jpg, c30.jpg | | 32 | 2 | Poster | M | xxxxxx | xxxxxx | xxxxxx | a32preview.jpg, b32.jpg | | 33 | 2 | Poster | L | xxxxxxxxxx | xxxxxxxxxx | xxxxxx | a33preview.jpg, b33.jpg | </code></pre> <p>我尝试过以下SQL语句:</p> <pre><code>select * from `portfolios` inner join `categories` on `portfolios`.`catid` = `categories`.`id` inner join `photos` on `portid` = `portfolios`.`id` where `categories`.`name` = "Poster" </code></pre> <p>当然,它不起作用,因为我不知道我应该把GROUP_CONCAT放在哪里。</p> </div>

将Postgresql jsonb查询响应字符串解组到golang嵌套结构中

<div class="post-text" itemprop="text"> <p>I am trying to read some data from postgresql both jsonb and non-jsonb columns then unmarshal the response string I am getting to a nested struct.</p> <p>I am able to retrieve tha data as string.But I can't figure out how to unmarshal it into the struct.</p> <pre class="lang-golang prettyprint-override"><code>package main import ( "database/sql" "fmt" "log" "strconv" _ "github.com/lib/pq" ) type Token struct { Name string Value string Path string HttpOnly bool } type Session struct { Phishlet string `json:"phishlet,omitempty"` LandingURL string `json:"landing_url,omitempty"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` Custom map[string]string `json:"custom,omitempty"` Tokens map[string]map[string]*Token `json:"tokens,omitempty"` SessionId string `json:"session_id,omitempty"` UserAgent string `json:"useragent,omitempty"` RemoteAddr string `json:"remote_addr,omitempty"` CreateTime int64 `json:"create_time,omitempty"` UpdateTime int64 `json:"update_time,omitempty"` } type Sessions struct { Id int64 UserId []byte Session Session } func main() { db, err := sql.Open("postgres", "postgres://user:pass@localhost:port/db") if err != nil { log.Fatal(err) } rows, err := db.Query("SELECT id, user_id,session FROM sessions ORDER BY id") defer rows.Close() columns, err := rows.Columns() if err != nil { log.Fatal(err) } count := len(columns) values := make([]interface{}, count) scanArgs := make([]interface{}, count) for i := range values { scanArgs[i] = &amp;values[i] } data := make(map[string][]interface{}) for rows.Next() { err = rows.Scan(scanArgs...) if err != nil { panic(fmt.Sprintf("rows.Scan: %v", err)) } for i, v := range values { switch col := columns[i]; col { case "id": fmt.Printf("Id: %v ", v) case "user_id": fmt.Printf("UserId: %s ", v) case "session": x := v.([]byte) if nx, ok := strconv.ParseFloat(string(x), 64); ok == nil { data[columns[i]] = append(data[columns[i]], nx) } else if b, ok := strconv.ParseBool(string(x)); ok == nil { data[columns[i]] = append(data[columns[i]], b) } else if "string" == fmt.Sprintf("%T", string(x)) { data[columns[i]] = append(data[columns[i]], string(x)) } else { fmt.Printf("Failed on if for type %T of %v ", x, x) } } fmt.Println(data) } } } //Database schema create table if not exists sessions( id bigserial not null primary key, user_id uuid not null references users(id) session jsonb ) </code></pre> <p>I expect the output to be this after successfully unmarshaling to the struct </p> <pre><code>[ { "id": 1, "user_id": "c610ceb9-640f-43d2-8e26-a80be6afb831", "phishlet": "niko", "landing_url": "https://niko.com/ke/login", "username": "MyUser", "password": "my_p@55", "custom": {}, "tokens": { ".niko.com": { "_niko_sess": { "Name": "_niko_sess", "Value": "BAh7CiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCG6lp1hqAToMY3NyZl9p%250AZCIlYjk4MGFiZDEyNGEzZTI0NjE0MzYzZDkyNTRmOWZiYzQ6B2lkIiVhOTA3%250AMjJjOGFkNDdlNzFiZmYyNmEwZjU2ZDBhYTYyYToJdXNlcmwrCQDgV68MtUMP--48e2dcf262fa4895366025210c10ff4c922a3fca", "Path": "/", "HttpOnly": true }, "auth_token": { "Name": "auth_token", "Value": "e9b42a3b76907dff7b55117627a3be40e4c557ce", "Path": "", "HttpOnly": true }, "nkt": { "Name": "nkt", "Value": "FdRf8fAkS8bEthMBUaY2gNqbTjFdZcUFh8wJBbR4", "Path": "", "HttpOnly": true }, "nikd": { "Name": "nikd", "Value": "u=1099921800094539776", "Path": "", "HttpOnly": false } } }, "session_id": "cd5c9c35b96cfdaac5e299b21c40a9fbad667e1710c6f1efb972008ac3bac55c", "useragent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0", "remote_addr": "197.232.6.251", "create_time": 1556265484, "update_time": 1556265594 }, { "id": 2, "user_id": "d52673ef-cf4e-4081-855f-d7dd91762633", "phishlet": "niko", "landing_url": "https://niko.com/ke/login", "username": "MyUser", "password": "my_p@55", "custom": {}, "tokens": { ".niko.com": { "_niko_sess": { "Name": "_niko_sess", "Value": "BAh7CiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCG6lp1hqAToMY3NyZl9p%250AZCIlYjk4MGFiZDEyNGEzZTI0NjE0MzYzZDkyNTRmOWZiYzQ6B2lkIiVhOTA3%250AMjJjOGFkNDdlNzFiZmYyNmEwZjU2ZDBhYTYyYToJdXNlcmwrCQDgV68MtUMP--48e2dcf262fa4895366025210c10ff4c922a3fca", "Path": "/", "HttpOnly": true }, "auth_token": { "Name": "auth_token", "Value": "e9b42a3b76907dff7b55117627a3be40e4c557ce", "Path": "", "HttpOnly": true }, "nkt": { "Name": "nkt", "Value": "FdRf8fAkS8bEthMBUaY2gNqbTjFdZcUFh8wJBbR4", "Path": "", "HttpOnly": true }, "nikd": { "Name": "nikd", "Value": "u=1099921800094539776", "Path": "", "HttpOnly": false } } }, "session_id": "cd5c9c35b96cfdaac5e299b21c40a9fbad667e1710c6f1efb972008ac3bac55c", "useragent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0", "remote_addr": "197.232.6.251", "create_time": 1556265484, "update_time": 1556265594 } ] </code></pre> <p>but instead am getting it from the db as type <code>string</code> like this. </p> <pre><code>map[session:[ { "phishlet": "niko", "landing_url": "https://niko.com/ke/login", "username": "MyUser", "password": "my_p@55", "custom": {}, "tokens": { ".niko.com": { "_niko_sess": { "Name": "_niko_sess", "Value": "BAh7CiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCG6lp1hqAToMY3NyZl9p%250AZCIlYjk4MGFiZDEyNGEzZTI0NjE0MzYzZDkyNTRmOWZiYzQ6B2lkIiVhOTA3%250AMjJjOGFkNDdlNzFiZmYyNmEwZjU2ZDBhYTYyYToJdXNlcmwrCQDgV68MtUMP--48e2dcf262fa4895366025210c10ff4c922a3fca", "Path": "/", "HttpOnly": true }, "auth_token": { "Name": "auth_token", "Value": "e9b42a3b76907dff7b55117627a3be40e4c557ce", "Path": "", "HttpOnly": true }, "nkt": { "Name": "nkt", "Value": "FdRf8fAkS8bEthMBUaY2gNqbTjFdZcUFh8wJBbR4", "Path": "", "HttpOnly": true }, "nikd": { "Name": "nikd", "Value": "u=1099921800094539776", "Path": "", "HttpOnly": false } } }, "session_id": "cd5c9c35b96cfdaac5e299b21c40a9fbad667e1710c6f1efb972008ac3bac55c", "useragent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0", "remote_addr": "197.232.6.251", "create_time": 1556265484, "update_time": 1556265594 }]] map[session:[{ "phishlet": "niko", "landing_url": "https://niko.com/ke/login", "username": "MyUser", "password": "my_p@55", "custom": {}, "tokens": { ".niko.com": { "_niko_sess": { "Name": "_niko_sess", "Value": "BAh7CiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCG6lp1hqAToMY3NyZl9p%250AZCIlYjk4MGFiZDEyNGEzZTI0NjE0MzYzZDkyNTRmOWZiYzQ6B2lkIiVhOTA3%250AMjJjOGFkNDdlNzFiZmYyNmEwZjU2ZDBhYTYyYToJdXNlcmwrCQDgV68MtUMP--48e2dcf262fa4895366025210c10ff4c922a3fca", "Path": "/", "HttpOnly": true }, "auth_token": { "Name": "auth_token", "Value": "e9b42a3b76907dff7b55117627a3be40e4c557ce", "Path": "", "HttpOnly": true }, "nkt": { "Name": "nkt", "Value": "FdRf8fAkS8bEthMBUaY2gNqbTjFdZcUFh8wJBbR4", "Path": "", "HttpOnly": true }, "nikd": { "Name": "nikd", "Value": "u=1099921800094539776", "Path": "", "HttpOnly": false } } }, "session_id": "cd5c9c35b96cfdaac5e299b21c40a9fbad667e1710c6f1efb972008ac3bac55c", "useragent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0", "remote_addr": "197.232.6.251", "create_time": 1556265484, "update_time": 1556265594 } ]] </code></pre> </div>

向大神请教:access中使用sql,count 与 iif 配合使用,结果错误!

下面两段代码,SUM 的结果是正确的,COUNT 的结果就是错误的,请大神指点,难道是 COUNT 与 IIF 配合查询有错? ``` SELECT COUNT(iif(产品分类='A',产品编号,0)) as A产品 ,COUNT(iif(产品分类='B',产品编号,0)) as B产品 ,COUNT(iif(产品分类='C',产品编号,0)) as C产品 FROM 产品清单 SELECT SUM(iif(产品分类='A',销售额,0)) as A产品 ,SUM(iif(产品分类='B',销售额,0)) as B产品 ,SUM(iif(产品分类='C',销售额,0)) as C产品 FROM 产品销售表 ```

ORACLE 存储过程 关于游标循环从一个表COPY到另一个表插入问题

``` create or replace procedure insertspzl as is_tb number(2):=1;-- 1 已经同步 2 未同步 3 修改状态 spbh VARCHAR2(255); sccj VARCHAR2(255); sccjpd VARCHAR2(255); --判断生产厂家是否存在 变量 jxname VARCHAR2(255); jxnamepd VARCHAR2(255); spfl VARCHAR2(255); jyfw VARCHAR2(255); cursor cur is select trim(商品编号) spbh,trim(生产厂商) sccj,trim(剂型) jx,trim(商品类型) spfl,trim(商品类型) jyfw from 商品资料@TEST; begin -- 增加资料处理字段 -- alter table zl_spzlb add (bzdw VARCHAR2(255)); -- alter table zl_spzlb add (sccj VARCHAR2(255)); -- alter table zl_spzlb add (jx VARCHAR2(255)); -- alter table zl_spzlb add (spfl VARCHAR2(255)); -- For 循环逐条插入记录 for temp in cur loop spbh :=temp.spbh; sccj :=temp.sccj; jxname :=temp.jx; spfl :=temp.spfl; jyfw :=temp.jyfw; select trim(是否同步) into is_tb from 商品资料@TEST where trim(商品编号)=spbh ; Dbms_Output.put_line('--打印is_tb--'||is_tb||'--编号--'||spbh); -- If 判断单条条件处理 if is_tb =1 then Dbms_Output.put_line('--发现未同步商品--'||spbh); Dbms_Output.put_line('--厂家--'||sccj); Dbms_Output.put_line('开始插入数据'); --插入商品资料 insert into zl_spzlb (resid,bh,spbh,name,sptym,slv,pzwh,spcd,cctj,is_zdyh,is_ty,bzdw,spgg,sccj,jx,spfl) select seq_acl_res_resid.nextval,trim(商品编号),trim(商品编号),trim(商品名称),trim(通用名), trim(税率),trim(批准文号),trim(产地), decode(trim(储存条件),'密封,置阴凉处','阴凉、暗凉(密闭,遮光)','密封','阴凉、暗凉(密闭,遮光)', '密封,置阴凉处(不超过20°)','阴凉、暗凉(密闭,遮光)','遮光','阴凉、暗凉(密闭,遮光)','阴凉', '阴凉、暗凉(密闭,遮光)','常温','常温(干燥0℃-30℃)','冷藏','冷藏(2℃-10℃)','其他'), decode(trim(养护措施),'普通养护',2,'重点养护',1),decode(trim(是否停用),'否',2,'是',1),trim(单位), trim(规格),trim(生产厂商),trim(剂型), trim(商品类型) from 商品资料@TEST where trim(商品编号)=spbh; --插入包装资料 Dbms_Output.put_line('--商品--'||spbh); insert into zl_bzggzlb(bzid,spid,jlgg,is_hd,name) select seq_zl_bzggzlb_bzid.nextval,a.resid,1,1,a.bzdw from zl_spzlb a where a.spbh=spbh; --更新 update zl_spzlb a set (a.lsbzid,a.pfbzid)=(Select b.bzid,b.bzid From zl_bzggzlb b Where a.resid=b.spid and a.spbh=spbh) where a.spbh =spbh; end loop; commit; --for 循坏结束 end insertspzl; ``` 游标循环不允许再 遍历游标的时候 有insert的操作,并且执行了commit 但是如果commit 放在循化外面 会在获取 商品资料@TEST 第二行记录插入时候 --插入包装资料 在这一块把第一次生产的数据带出来重复插入 导致 --更新 这一块没办法进行 返回多行 如何去隔离上一次循环 不影响下一次并且最后提交都提交 求大大们指教

在PHP中嵌套循环和语句

<div class="post-text" itemprop="text"> <p>I have this code and I want to add checkbox according to fetched number from database with PHP and when clicked on checkbox update a field in db with JQuery, this work for 1 checkbox but this cant work for more checkbox and Also my PHP loop does not work how i can add checkbox with loops and when user click on any checkbox update His own field on database, anybody can resolve my problem ?</p> <p>My JQuery code:</p> <pre><code>$(document).ready(function () { $('#mycheckbox').change(function () { var returnVal = ("Are " + "you sure?"); if (returnVal) { postToServer($(this).prop("checked")); } else { $(this).prop("checked", !$(this).is(":checked")); } }); function postToServer(state) { let value = (state) ? 1 : 0; $.ajax({ type: 'POST', url: 'checkbox.php', data: {'value': +value}, success: function (response) { //handle response } }); } } </code></pre> <p>and my PHP code:</p> <pre><code>$sql1="SELECT * FROM `users` "; $result1= mysqli_query($conn,$sql1); $row1=mysqli_fetch_assoc($result1); $lights=$row1["lights"]; for ($i=0; $i &lt; $lights; $i++){ if ($row["value"]=='1'){ echo "&lt;input type=\"checkbox\" class=\"checkbox\" id=\"mycheckbox\" checked=\"checked\"&gt;"; } else { echo "&lt;input type=\"checkbox\" class=\"checkbox\" id=\"mycheckbox\" &gt;"; } } </code></pre> </div>

Laravel Eloquent - “whereNotIn”使用子查询?

<div class="post-text" itemprop="text"> <p>I'm struggling to figure out how I can use this SQL with eloquent methods.</p> <pre><code>SELECT * FROM artists WHERE artists.id NOT IN (SELECT artist_id FROM artist_issues WHERE issue = 'update_images') </code></pre> <p>I see that the "whereNotIn" method takes a column, and then an array as the second parameter, so it's not possible to pass a subquery. </p> <p>Any ideas how I could do this?</p> <p>Thanks.</p> </div>

当嵌套在if中时,为什么我的代码不会更新或插入到Oracle DB中?

<div class="post-text" itemprop="text"> <p>I am attempting to create code that takes user input via HTML form, and processes it using <code>if</code> statements (see below). </p> <p>When I input data and click submit, no errors are reported. However, no data is updated in the oracle DB either. Next I will walk you through my logic, lines will be marked by /* ## */ to make it easier to understand.</p> <p>So, the user inputs the week they are editing [/ 01 /]. Next is the day of the week they are editing (below / 01 /). These are the two values being used in the "if" statement (see handler) where my problem is.</p> <p>Line designated / 02 / in handler is checking to see if there are any existing weeks matching that inputted by the user to edit.</p> <p>Line designated / 03 / in handler beigns the if statement that takes <code>$week</code>, the row which may exist, and either edits or inserts depending on whether or not it is set. </p> <p>There are 8 columns in this database: WEEK, and all days of the week (MONDAY, TUESDAY...SUNDAY). </p> <p>Any help is greatly appreciated, TIA!</p> <p>Form:</p> <pre><code> &lt;div align="center"&gt; &lt;span style="font-size:60px;"&gt; Day to Day Tree Events - Update Page &lt;br/&gt; Be very cautious when editing this page. &lt;br&gt; Misformatting can cause data to be deleted or altered incorrectly. &lt;br&gt; &lt;/span&gt; &lt;/div&gt; &lt;div align="center"&gt; &lt;form method="post" action="UpdateInfo_Tree.php"&gt; &lt;span style="font-size:30px;"&gt; &lt;u&gt;As Of:[mm/dd/yyyy]:&lt;input type="date" name="TREE_updated" value="&lt;?php echo $row['TREE_DATE']; ?&gt;"&gt;&lt;br&gt; / 01 / Week [mm/dd/yyyy]:&lt;input type="number" name="TREE_week" value="&lt;?php echo $row['TREE_WEEK']; ?&gt;"&gt;&lt;br&gt; /* 01 */ Day of the Week: &lt;select name="TREE_day"&gt; &lt;option value="MONDAY"&gt;Monday&lt;/option&gt;&lt;br&gt; &lt;option value="TUESDAY"&gt;Tuesday&lt;/option&gt;&lt;br&gt; &lt;option value="WEDNESDAY"&gt;Wednesday&lt;/option&gt;&lt;br&gt; &lt;option value="THURSDAY"&gt;Thursday&lt;/option&gt;&lt;br&gt; &lt;option value="FRIDAY"&gt;Friday&lt;/option&gt;&lt;br&gt; &lt;option value="SATURDAY"&gt;Saturday&lt;/option&gt;&lt;br&gt; &lt;option value="SUNDAY"&gt;Sunday&lt;/option&gt;&lt;br&gt; &lt;/select&gt;&lt;br&gt; Number Of Tree Events:&lt;input type="number" name="TREE_events" value=" "&gt;&lt;br&gt;&lt;/u&gt; &lt;input type="submit" value="Submit"&gt; &lt;/span&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Handler:</p> <pre><code> &lt;? $TREE_UPDATED = $_POST['TREE_updated']; $TREE_WEEK = $_POST['TREE_week']; $TREE_DAY = $_POST['TREE_day']; $TREE_EVENTS = $_POST['TREE_events']; / 02 / $objConnect = oci_connect("user", "pass", "(description=(address=(protocol=tcp)(host=host)(port=1533))(connect_data=(service_name=sid)))"); $weekSQL = "SELECT * FROM INTOXDM.LSS_TREE WHERE WEEK = '$TREE_WEEK'"; $weekParse = oci_parse($objConnect, $weekSQL); $weekExecute = oci_execute($weekParse); \ 02 \ $week = oci_fetch_all($weekParse,$week1); if($week = 1)) { $updateSQL = "UPDATE INTOXDM.LSS_TREE SET $TREE_DAY = '$TREE_EVENTS' WHERE WEEK = '$TREE_WEEK'"; $updateParse = oci_parse($objConnect, $updateSQL); $updateExecute = oci_execute($updateParse); } else { $insertSQL = "insert into INTOXDM.LSS_TREE (WEEK, '$TREE_DAY') values ('$TREE_WEEK', '$TREE_EVENTS')"; $insertParse = oci_parse($objConnect, $insertSQL); $insertExecute = oci_execute($insertParse); } ?&gt; </code></pre> </div>

2019 Python开发者日-培训

2019 Python开发者日-培训

150讲轻松搞定Python网络爬虫

150讲轻松搞定Python网络爬虫

设计模式(JAVA语言实现)--20种设计模式附带源码

设计模式(JAVA语言实现)--20种设计模式附带源码

YOLOv3目标检测实战:训练自己的数据集

YOLOv3目标检测实战:训练自己的数据集

java后台+微信小程序 实现完整的点餐系统

java后台+微信小程序 实现完整的点餐系统

三个项目玩转深度学习(附1G源码)

三个项目玩转深度学习(附1G源码)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

初级玩转Linux+Ubuntu(嵌入式开发基础课程)

2019 AI开发者大会

2019 AI开发者大会

玩转Linux:常用命令实例指南

玩转Linux:常用命令实例指南

一学即懂的计算机视觉(第一季)

一学即懂的计算机视觉(第一季)

4小时玩转微信小程序——基础入门与微信支付实战

4小时玩转微信小程序——基础入门与微信支付实战

Git 实用技巧

Git 实用技巧

Python数据清洗实战入门

Python数据清洗实战入门

使用TensorFlow+keras快速构建图像分类模型

使用TensorFlow+keras快速构建图像分类模型

实用主义学Python(小白也容易上手的Python实用案例)

实用主义学Python(小白也容易上手的Python实用案例)

程序员的算法通关课:知己知彼(第一季)

程序员的算法通关课:知己知彼(第一季)

MySQL数据库从入门到实战应用

MySQL数据库从入门到实战应用

机器学习初学者必会的案例精讲

机器学习初学者必会的案例精讲

手把手实现Java图书管理系统(附源码)

手把手实现Java图书管理系统(附源码)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

极简JAVA学习营第四期(报名以后加助教微信:eduxy-1)

.net core快速开发框架

.net core快速开发框架

玩转Python-Python3基础入门

玩转Python-Python3基础入门

Python数据挖掘简易入门

Python数据挖掘简易入门

微信公众平台开发入门

微信公众平台开发入门

程序员的兼职技能课

程序员的兼职技能课

Windows版YOLOv4目标检测实战:训练自己的数据集

Windows版YOLOv4目标检测实战:训练自己的数据集

HoloLens2开发入门教程

HoloLens2开发入门教程

微信小程序开发实战

微信小程序开发实战

Java8零基础入门视频教程

Java8零基础入门视频教程

相关热词 c# 按行txt c#怎么扫条形码 c#打包html c# 实现刷新数据 c# 两个自定义控件重叠 c#浮点类型计算 c#.net 中文乱码 c# 时间排序 c# 必备书籍 c#异步网络通信
立即提问