sql查询 生成列号

select @row_num totalcount,1 as pageIndex, 3 as pageSize,result_order.*
from account_report as ar inner join (
select @row_num:[email protected]_num+1 AS row_num ,a.name as aName,a.transaction_type,r.report_date,r.name as rName,r.submit_time,r.deadline,r.`status`,r.id as reportId
from account a,account_report r ,(SELECT @row_num:=0) AS rowvar
where r.account_id=a.id and a.transaction_type in (2) and r.`status` in (0) and r.`type` in (0)
)
AS result_order on ar.id=result_order.reportId

and result_order.row_num>(3*(1-1)) and result_order.row_num<=(3*1)
order by result_order

时间: 2024-08-02 13:17:14

sql查询 生成列号的相关文章

SQL查询显示行号、随机查询、取指定行数据

1.显示行号 如果数据没有删除的情况下主键与行号是一致的,但在删除某些数据,行号就与主键不一致了,这时需要查询行号就需要用新的方法,在SQL Server2005之前,需要使用临时表,但在SQL Server2005中,使用ROW_NUMBER()非常方便. select row_number() over (order by UseriD) as rowNum,* from UserInfo 查询结果: 2.随机查询 有的时候我们需要查询出的数据是随机排序的,newid()函数在扫描每条记录时

hive SQL查询结果添加行号

用窗口函数可以解决这个问题: 例:select row_number() over(order by user_id desc) ,tab.* from dws_user_visit_month1 as tab limit 20; 结果: 其实要是单纯想加一个自增的行号,没有顺序要去的话 over()里面可以空着 例:select row_number() over(),tab.* from dws_user_visit_month1 as tab limit 20; 解决:        可以

用SQL存储过程生成唯一单据号

在一些系统中,经理要生成单据号,为了不使多台客户端生成的单据号重复,一般要在服务端生成这种流水号,本文是在数据库中生成流水号,并且可以生成多种类型的单据号(比如销售单据号,盘点单据号,进货单据号等),利用数据库锁的原理,先看一下SQL语句: CREATE PROC [dbo].[getlsh]     @lx VARCHAR(6) ,     @lsh VARCHAR(30) OUTPUT AS     BEGIN  --启动事务处理         [email protected]_poin

查询sql时 改变列原来的类型

查询sql时 改变列原来的类型SELECT   create_time   FROM    ciimp_fin_invoice               本来要查询的 是 创建时间 时间类型 结果为 2017-03-29 03:29:40 SELECT create_time+'' FROM ciimp_fin_invoice 在sql列中 +'' 将其列改变为字符串类型,输出的结果为:20170329032940    + 可扩展 字符串.数字.时间 类型都可以

sql查询时加上行号

sql查询时加上行号 sql查询的时候有时候要加上行号,这里做个备忘~ 1(建议采用),select row_number() over (order by col1) as no,newid() as id,*from Table1order by col1 2,select no=identity(int,1,1),newid() as id,* into  #temptable From  Table1order by col1Select * From #temptableDrop Ta

SQL查询语句行转列横向显示

SQL查询语句行转列横向显示 2011-03-15 10:00:14|  分类: sql |  标签:resource   |举报 |字号大中小 订阅 在SQL查询语句行转列横向显示中access中没有CASE,要用IIF代替 select  iif(sex= '1 ', '男 ', '女 ')  from  tablename 示例1: select country, sum(case when type='A' then money end) as A, sum(case when type

SQL 行转列查询汇总

SQL行转列汇总 PIVOT 用于将列值旋转为列名(即行转列),在 SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT 的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P 注意:PIVOT.UNPIVOT是SQL Server 2005 的语法,使用需修改数据库兼容级别(在数据库属性->选项->兼容级别改为 90 ) SQL2008 中可以直接使用 完整语法: table_source PIVOT( 聚合函数(value_column) F

SQL查询条件生成小工具

最近运维数据,经常遇到需要在sql条件中个In('',''....)个字符串的情况,于是在网上找了个小工具改造一下,先用着: 效果如图: 1 using System; 2 using System.Collections.Generic; 3 using System.IO; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7 using Newtonsoft.Json.Serializatio

Microsoft SQL - 查询与更新

查询与更新(Query & Update) 查询(Inquire) 以下公式中的c指代列名. 规则 1.查询语句的列名区分大小写. 2.查询语句的字符串只能使用单引号. 3.为每条语句加上分号表示一条语句结束,防止当一次执行多条语句时会抛错. 关键字:select 三种基本查询格式 直接查询 select * from stu 参数查询 将查询语句作为字符参数传递给exec执行函数 exec('select * from stu') declare @name varchar(10) , @en