sql查询一张表,根据不同的id取出两组数据,比较着两组数据中的一个相同的字段,相等就想加,否则就合并

sql查询一张表,根据不同的id取出两组数据,比较着两组数据中的一个相同的字段,相等就想加,否则就合并,第1张

create table #temp(id int,name varchar(10),total int)

go

insert into #temp values(1,'kate',200)

insert into #temp values(1,'lily',500)

insert into #temp values(2,'kate',300)

insert into #temp values(2,'lily',100)

insert into #temp values(2,'lulu',200)

insert into #temp values(2,'anly',300)

go

with tb as (

select ROW_NUMBER() over(order by count(1)) id,name,SUM(total) total,COUNT(1) nums from #temp group by name 

)

select t1name+t2name,t1total+t2total from (

select  from tb where nums=1 and id%2=0)t1 inner join (select  from tb where nums=1 and id%2=1) t2

on t1nums=t2nums

union all

select name,total from tb where nums=2

你看看参考一下,不过这个不全面,还是有缺陷的。

根据id

读出数据库信息??select

from

XXX

where

id

=

XXX

这样就读出来啦。。。。。。可以把参数id放在url上

然后get下来。。然后去数据库查。。。。然后显示。。这样就对应了

查看原帖>>

这是sina同事xiaoniu发现的,如下

代码如下:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8"/>

</head>

<body>

<div

id="02E503E2A1C011CFC85B7B701A0677EC0900000000000001"></div>

<script>

var str =

'02E503E2A1C011CFC85B7B701A0677EC0900000000000001';

function bySelector(id)

{

return documentquerySelector('#'+id);

}

function byId(id) {

return documentgetElementById(id);

}

alert(bySelector(str));

alert(byId(str));

</script>

</body>

</html>

两个函数bySelector,byId分别通过querySelector和getElementById获取元素

页面上有id为“02E503E2A1C011CFC85B7B701A0677EC0900000000000001”的元素。

结果:所有支持querySelector的浏览器中通过bySelector均获取不到(报错),但通过getElementById却可以获取。

开始怀疑是id的字符串太长的原因导致querySelector获取不到。真正原因却是querySelector按css规范实现,即css标识符也不能以数字开头。

W3 写道

In CSS, identifiers (including element names, classes, and IDs

in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646

characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they

cannot start with a digit, two hyphens, or a hyphen followed by a digit

Identifiers can also contain escaped characters and any ISO 10646 character as a

numeric code (see next item) For instance, the identifier "B&W" may be

written as "B\&W\" or "B\26 W\3F"

以上就是关于sql查询一张表,根据不同的id取出两组数据,比较着两组数据中的一个相同的字段,相等就想加,否则就合并全部的内容,包括:sql查询一张表,根据不同的id取出两组数据,比较着两组数据中的一个相同的字段,相等就想加,否则就合并、php求助:如何通过id获取数据库内容,并显示到网页上来、querySelector和getElementById通过id获取元素的区别等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9663762.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存