首页 > 数据库 >sql

sql

时间:2022-08-18 12:01:11浏览次数:44  
标签:yyid SUM bill month sql ORDER select

    select * from Appointment where yyid in ('2021051100000012','2021051900000018','2021052100000021')
    用以下代替:
    
    select * FROM Appointment  a JOIN (
 select '2021051100000012' yyid  union select '2021051900000018'  UNION  SELECT '2021052100000021' ) b 
  on  a.yyid=b.yyid
select a.* from Appointment a where a.yyid in(select yyid from OrderPayment where ReceivableAmount=3000 )
     用下面的语句替换:
     select a.* from Appointment a where 1=1 and  exists(select 1 from OrderPayment where yyid=a.yyid and ReceivableAmount=3000 )

 

SELECT
    * 
FROM
    phonebill --取出每月通话费最高和最低的两个地区。
SELECT TOP
    2 * 
FROM
    phonebill 
WHERE
    net_type = 'G' 
GROUP BY
    bill_month 
ORDER BY
    area_code DESC SELECT
    BILL_MONTH,
    AREA_CODE,
    SUM ( LOCAL_FARE ) LOCAL_FARE,
    FIRST_VALUE ( AREA_CODE ) OVER ( PARTITION BY BILL_MONTH ORDER BY SUM ( LOCAL_FARE ) DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) FIRSTVAL,
    LAST_VALUE ( AREA_CODE ) OVER ( PARTITION BY BILL_MONTH ORDER BY SUM ( LOCAL_FARE ) DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) LASTVAL 
FROM
    phonebill 
GROUP BY
    BILL_MONTH,
    AREA_CODE 
ORDER BY
    BILL_MONTH SELECT
    bill_month,
    area_code,
    SUM ( local_fare ) local_fare,
    first_value ( area_code ) OVER ( partition BY bill_month ORDER BY SUM ( local_fare ) DESC ROWS BETWEEN unbounded preceding AND unbounded following ) firstval,
    last_value ( area_code ) OVER ( partition BY bill_month ORDER BY SUM ( local_fare ) DESC ROWS BETWEEN unbounded preceding AND unbounded following ) lastval 
FROM
    phonebill 
GROUP BY
    bill_month,
    area_code 
ORDER BY
    bill_month SELECT
    bill_month,
    area_code,
    SUM ( local_fare ) local_fare 
FROM
    phonebill a 
GROUP BY
    bill_month,
    area_code 
ORDER BY
    bill_month SUM ( loc_fare )
    
    
    
    
View Code

 

标签:yyid,SUM,bill,month,sql,ORDER,select
From: https://www.cnblogs.com/dyxinfo/p/16546593.html

相关文章

  • SQL Server—单表查询
    1.查询一个表的所有数据。【select*from表名】select*fromUserinfo2.查询一个表的部分数据。【select列名,列名,…from表名】selectUserName,Ag......
  • SQL SERVER 附加数据库时报错(5123,5120):无法打开物理文件……操作系统错误,拒绝访问…
      这属于权限不够。找到数据库文件,右键属性-安全,会发现没有权限查看: 点击“高级”——“继续”——“添加”——“选择主体”——“高级”——“立即查找”——选......
  • 查看特定表的备注--postgresql
    1. 获取字段名、类型、注释、是否为空SELECT col_description(a.attrelid,a.attnum)ascomment, format_type(a.atttypid,a.atttypmod)astype, a.attnameasname......
  • 评分管理系统环境部署:JDK1.8,nginx:1.14.0,redis 6.2.4 ,mysql 8.0.22
    背景:环境要求服务器上部署项目,需要JDK1.8,nginx:1.14.0,redis6.2.4,mysql8.0.22,使用在线安装版本或者docker版本;linux的版本是CentOs7.4(cat/etc/redhat-release);jdk......
  • sql语句查询
    xxxImpl.java 继承IDao<xxx>以qqUser为例publicclassqqDaoImplimplementsIDao<qqUser>{@Overridepublicintinsert(qqUserqqUser)throwsSQLExcep......
  • mysql外键约束 删除
    mysql海量表的创建CREATETABLEdept(/*部门表*/deptnoMEDIUMINTUNSIGNEDNOTNULLDEFAULT0,dnameVARCHAR(20)NOTNULLDEFAULT"",locVARCHAR(13)NOT......
  • SQL Server遍历表的几种方法
    在数据库开发过程中,我们经常会碰到要遍历数据表的情形,一提到遍历表,我们第一印象可能就想到使用游标,使用游标虽然直观易懂,但是它不符合面向集合操作的原则,而且性能也比面向......
  • sql注入之union注入
    联合查询注入利用的前提:必须要有回显联合查询过程:判断是否存在注入点判断是什么类型注入(字符型or数字型)判断闭合方式查询列数个数(orderby)获得数据库名获得......
  • SQL注入的基本原理
          SQL注入是常见的网络攻击方法,之所以能够实现,是因为网页有着SQL漏洞。那么什么是SQL漏洞呢,理解SQL注入以及SQL漏洞就要从注入的基本概念和原理说起,Union联......
  • 6.2 SQL Server更新数据
    SQLServerUPDATE目录SQLServerUPDATE简介示例UPDATEJOINUPDATEJOIN示例A)SQLServerUPDATEINNERJOIN示例B)SQLServerUPDATELEFTJOIN示例简介要修改表中的......