//查询账单关联订单
select
o.id as id,
o.order_no as orderNo,
o.case_no as caseNo,
o.send_time as sendTime,
o.final_time as finalTime,
(select ca.car_no from fm_order_case ca where ca.case_no = o.case_no) as carNo,
(select co.service_money from fm_order_cost co where co.order_id = o.id ) as serviceMoney
from fm_order o
where o.id IN (
select bo.order_id from ac_bill_order bo where bo.bill_id = 3
) //发票 账单 机构信息联查
SELECT
g.org_name as orgName,
b.bill_seq as billSeq,
b.order_count as orderCount,
b.invoice_stat as invoiceStat,
a.invoice_title as invoiceTitle,
a.invoice_type as invoiceType,
a.invoice_company as invoiceCompany,
a.invoice_content as invoiceContent,
a.invoice_money as invoiceMoney,
a.apply_time as applyTime
FROM ac_invoice_apply a
LEFT JOIN ac_bill b ON b.id = a.bill_id
LEFT JOIN ct_group g ON g.user_id = b.user_id //查询基准id
SELECT
max(b.id)
FROM
ac_bill b
WHERE
b.user_id = 59
AND
b.bad_debt_id is not null //查询待插入的账单id
SELECT
b.id
FROM
ac_bill b
WHERE
b.id>6
and
b.user_id = 59 //查询催款单时间段
SELECT DISTINCT
(
select b.start_time from ac_bill b
where b.id = (
select min(b.id) from ac_bill b where b.id > 6 and b.user_id = 59
)
) as startTime,
(
select b.end_time from ac_bill b
where b.id = (
select max(b.id) from ac_bill b where b.id > 6 and b.user_id = 59
)
) as endTime
FROM ac_bill b //查询催款时段累计金额
select sum(b.bill_money-b.deposit_money)
FROM ac_bill b
WHERE b.id in(
SELECT
b.id
FROM
ac_bill b
WHERE
b.id>6 and b.user_id = 59
) //查询催款时间短+累计金额
SELECT DISTINCT
(
select b.start_time from ac_bill b
where b.id = (
select min(b.id) from ac_bill b where b.id > 6 and b.user_id = 59
)
) as startTime,
(
select b.end_time from ac_bill b
where b.id = (
select max(b.id) from ac_bill b where b.id > 6 and b.user_id = 59
)
) as endTime,
(
select sum(b.bill_money-b.deposit_money)
FROM ac_bill b
WHERE b.id in(
SELECT
b.id
FROM
ac_bill b
WHERE
b.id> 6
and b.user_id = 59
)
) as totalMoney
FROM ac_bill b
left join ct_user u on u.id = b.user_id
WHERE b.user_id = 59 //查询与催款单关联的账单信息
select
*
from
ac_reminder_bill rb
LEFT JOIN
ac_bill b on rb.bill_id = b.id
where rb.reminder_id = 3 每月1号自动生成所有机构的上月账单
//查询完成订单ID
SELECT
o.id
FROM
fm_order o LEFT JOIN fm_order_cost c ON o.id = c.order_id
WHERE
o.buyer_user_id = 59
AND
o.deal_stat = ''
AND
YEAR(o.final_time) = 2014
AND
MONTH(o.final_time) = 6 //查询完成订单个数
SELECT
count(*)
FROM
fm_order o LEFT JOIN fm_order_cost c ON o.id = c.order_id
WHERE
o.buyer_user_id = 59
AND
o.deal_stat = ''
AND
YEAR(o.final_time) = 2014
AND
MONTH(o.final_time) = 6 //查询完成订单总金额
SELECT
sum(c.pay_money)
FROM
fm_order o LEFT JOIN fm_order_cost c ON o.id = c.order_id
WHERE
o.buyer_user_id = 59
AND
o.deal_stat = ''
AND
YEAR(o.final_time) = 2014
AND
MONTH(o.final_time) = 6 //查询用户上月充值总金额
SELECT
sum(d.deposit_money)
FROM
ac_deposit d
WHERE
d.user_id = 59
AND
d.deposit_stat = 1
AND
d.audit_stat = 2
AND
YEAR(d.deposit_time) = 2014
AND
MONTH(d.deposit_time) = 6 //sql合体,一个语句查询某月某用户的完成订单数 账单金额 充值金额
SELECT
ifnull(
(
SELECT count(*) FROM fm_order o
WHERE o.buyer_user_id = 59
AND o.deal_stat = ''
AND YEAR(o.final_time) = 2014
AND MONTH(o.final_time) = 6
),
''
) as orderCount,
ifnull(
(
SELECT sum(c.pay_money) FROM fm_order o
LEFT JOIN fm_order_cost c ON o.id = c.order_id
WHERE o.buyer_user_id = 59
AND o.deal_stat = ''
AND YEAR(o.final_time) = 2014
AND MONTH(o.final_time) = 6
),
''
) as billMoney,
ifnull(
(
SELECT sum(d.deposit_money) FROM ac_deposit d
WHERE d.user_id = 59
AND d.deposit_stat = 1
AND d.audit_stat = 2
AND YEAR(d.deposit_time) = 2014
AND MONTH(d.deposit_time) = 6
),
''
) as depositMoney
 

[mysql] 关联查询sql记录的更多相关文章

  1. Mysql资料 查询SQL执行顺序

    目录 一.Mysql数据库查询Sql的执行顺序是什么? 二.具体顺序 一.Mysql数据库查询Sql的执行顺序是什么? (9)SELECT (10) DISTINCT column, (6)AGG_F ...

  2. mysql 关联查询 索引不起作用原因记录

    业务逻辑如下:查询某篇文章的评论列表,且列出评论人及被评论人的昵称.头像. 先看一下表结构 评论表: 评论表的索引: 用户表: 用户表的索引: 查询语句如下: SELECT t1.comment_id ...

  3. MySQL关联查询总结

    MySQL中经常使用关联查询,有机会总结下: 1 left join(左联查询): 返回包括左表中的所有记录和右表中联接字段相等的记录 例:select * from a left join b on ...

  4. 查找Mysql慢查询Sql语句

    一.MySQL数据库有几个配置选项可以帮助我们及时捕获低效SQL语句 1,slow_query_log 这个参数设置为ON,可以捕获执行时间超过一定数值的SQL语句. 2,long_query_tim ...

  5. mysql如何配置sql记录

    原文链接:http://www.qqdeveloper.com/detail/11/1.html 为什么要记录sql记录 主要目的是为了检测我们的网站安全问题,有效的避免一些sql注入或者是xss攻击 ...

  6. mysql关联查询和联合查询

    一.内联方式 1.传统关联查询 "select * from students,transcript where students.sid=transcript.sid and transc ...

  7. MySQL☞关联查询

    关联查询:所需要的数据来源于多张表,通过表的连接查询(关联查询)来查询多张表中的数据 格式: select 别名1 . */列名 , 别名2 . */列名 from 表名1  别名1 , 表名2  别 ...

  8. mysql 慢查询日志记录

    环境: 操作系统: CentOS  6.5 数据库:    mysql-5.1.73 1.查看当前慢查询配置 mysql> show variables like 'slow%'; +----- ...

  9. mysql 关联查询技巧

    废话不多说,直接进入正题 #数据准备 班级表class: CREATE TABLE `class` ( `class_no` ) unsigned zerofill NOT NULL AUTO_INC ...

随机推荐

  1. 如何不让DataGridView自动生成列

    如果不想让DataGridView自动生成与数据源对应的列, 只需要把属性AutoGenerateColumns设为false即可. 需要注意: 在界面设计的属性窗口中是看不到AutoGenerate ...

  2. select函数的并发限制和 poll 函数应用举例

    一.用select实现的并发服务器,能达到的并发数,受两方面限制 1.一个进程能打开的最大文件描述符限制.这可以通过调整内核参数.可以通过ulimit -n来调整或者使用setrlimit函数设置,  ...

  3. TCP/IP协议栈与数据报封装

    一.ISO/OSI参考模型 OSI(open system interconnection)开放系统互联模型是由ISO(International Organization for Standardi ...

  4. jdbc与odbc的差别,感悟,学习。。。

    什么是JDBC? JDBC, 全称为Java DataBase Connectivity standard, 它是一个面向对象的应用程序接口(API), 通过它可訪问各类关系数据库.JDBC也是jav ...

  5. Java调用Linux命令(cd的处理)

    一.Java调用Linux系统的命令非常简单 这是一个非常常用的调用方法示例: public String executeLinuxCmd(String cmd) { System.out.print ...

  6. InnoDB Master Thread I/O Rate详解

    一.innodb 在刷盘时要面对的问题: 1.对于innodb 的master thread 这个线程来说,它会在后台执行许多的任务,这些任务大多数都是与IO操作相关的, 比如“刷新脏页到磁盘”.“合 ...

  7. Vim进阶技术:搜索和替换

    行内搜索 行内搜索,也就是在当前行内进行搜索和移动,通常都与编辑命令一起使用. fx -- 移动到下一个字符x的位置,光标停留在x字符上面 tx -- 移动到下一个字符x的位置,光标停留在x前一个字符 ...

  8. MySql按字段分组取最大值记录

    数据库原始数据如下:数据库名:tbl_clothers 需求是:按照type分组,并获取个分组中price中的最大值,解决sql如下: 方法一: select * from (select type, ...

  9. unity5 Edit Collider

    按下Edit Collider按钮,视图中Collider线框中出现控制点,可以通过拖动控制点对Collider进行调整.

  10. Jenkins 使用学习笔记

    3.1    Jenkins安装    2 3.1.1    Jenkins下载    2 3.1.2    Jenkins 安装    2 3.1.3    Jenkins 目录结构    3 3. ...