Ⅰ 如何用sql语句将下图1~7列的数据在month相同的情况下显示在同一行而不是隔行显示
select year(test1.order_head.ship_date) as year,month(test1.order_head.ship_date) as month,
sum(case when DATEPART ( weekday ,test1.order_head.ship_date)=2 then test1.order_body.totalmoney else 0 end) as [1],
sum(case when DATEPART ( weekday ,test1.order_head.ship_date)=3 then test1.order_body.totalmoney else 0 end) as [2],
sum(case when DATEPART ( weekday ,test1.order_head.ship_date)=4 then test1.order_body.totalmoney else 0 end) as [3],
sum(case when DATEPART ( weekday ,test1.order_head.ship_date)=5 then test1.order_body.totalmoney else 0 end) as [4],
sum(case when DATEPART ( weekday ,test1.order_head.ship_date)=6 then test1.order_body.totalmoney else 0 end) as [5],
sum(case when DATEPART ( weekday ,test1.order_head.ship_date)=7 then test1.order_body.totalmoney else 0 end) as [6],
sum(case when DATEPART ( weekday ,test1.order_head.ship_date)=1 then test1.order_body.totalmoney else 0 end) as [7]
from test1.order_body inner join
test1.order_head on test1.order_body.ord_id = test1.order_head.ord_id
where year(test1.order_head.ship_date)='2013' and test1.order_body.totalquan>0
group by year(test1.order_head.ship_date),month(test1.order_head.ship_date)
order by year,month
Ⅱ sql 查出相同的记录 并把相同记录 显示在一起
貌似你这个语句就已经可以查出所有的相同记录来了吧?
相同的记录显示在一起
可以加个排序
select * from 表1 where id in(select id from 表1 group by id having count(id)>1)
order by 相同记录的字段名 asc
如果不行可以HI我或追问。
Ⅲ SQL 两个表顺序显示
在select里分开查询就行了
SELECTA.*, B.*FROM A,B WHERE <condition>
Ⅳ SQL 语法,select 的时候如何指定 行的顺序
你可以在表中另加一列,比如叫 sequence,用int 类型,然后你就可以定义你需要的次序了。
只有 select * from table order by sequence, 就直接得到你需要的顺序。
Ⅳ SQL中数据行相邻且某一列的值相同则合并
Oracle
select distinct a,FIRST_VALUE (b) over(order by rownum) from t
MSSQL 也有FIRST_VALUE函数
Ⅵ 请教:SQL语句如何实现同一列里如果与上一行数据相同,则这一行该列数据不显示,但是其他列要照样显示。
declare@idint,@countchar(20)
print'id'+''+'count'
declareC_qcursorfor
selectdistinctidfromqqq
openC_q
fetchnextfromC_qinto@id
while@@fetch_status=0
begin
printcast(@idasvarchar(10))+':'
declareC_cursorfor
select[count]fromqqq
whereid=@id
openC_
fetchnextfromC_into@count
while@@fetch_status=0
begin
print''+@count
fetchnextfromC_into@count
end
closeC_
deallocateC_
print'======================'
fetchnextfromC_qinto@id
end
closeC_q
deallocateC_q
其实你要做报表使用游标是一个很好的选择。我采用的就是这个方法给你做的,效果一样。不会你再问。望采纳,谢谢!
Ⅶ sql 如何将字段相同的排列在一起
select字段1from表名orderby字段1
Ⅷ sql 表字段有相同数据怎么排列顺序
例如,按学生学号升序排列,学生成绩按降序排列
sql是这样写的:select
*
from
tab
order
by
id,scroe
desc
sql
server会根据order
by跟id
scroe
先后进行排序,
先根据id升序排序,再根据scroe降序排序,也许你会发现scroe列的数据不是按照降序排列
这就是优先排序的原则,order
by
后面谁在前,谁就优先排序
你可以仔细看看相同的id(你可以插入几行相同的id,不同scroe),score就是按照降序排列的
Ⅸ sql中如何实现相邻两行数据合并转换
select sum(case when wgrp_id='2' then quota end) w2, sum(case when wgrp_id='3' ;then quota end) w3, mm;from table;group by mm。
SQL语言,是结构化查询语言(Structured Query Language)的简称。SQL语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统;同时也是数据库脚本文件的扩展名。
SQL语言是高级的非过程化编程语言,允许用户在高层数据结构上工作。它不要求用户指定对数据的存放方法,也不需要用户了解具体的数据存放方式,所以具有完全不同底层结构的不同数据库系统可以使用相同的结构化查询语言作为数据输入与管理的接口。SQL语言语句可以嵌套,这使他具有极大的灵活性和强大的功能。
Ⅹ SQL如何同一行对于相同值,如何显示到我的第一行,其余行不显示
select t1.lot,isnull(t2.t_pur_qty,'') as pur_qty,isnull(t2.t_ruku,'') as ruku,t1.item_no,t1.part_type,t1.pri
from 表名 t1 left join (select top 1 lot as t_lot,pur_qty as t_pur_qty,ruku as t_ruku,item_no as t_item_no from 表名 group by lot,pur_qty,ruku,item_no) t2
on t1.lot=t2.t_lot and t1.item_no=t2.t_item_no
测试过,莫问题了