using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using Newtonsoft.Json; namespace CLibrary.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
var tableAAA = "[{\"companycode\":\"80463417\",\"securitycode\":\"603978\",\"securityshortname\":null,\"financecode\":null,\"purchasedate\":\"2017-07-26T00:00:00\",\"listingdate\":\"2017-08-07T00:00:00\",\"issueprice\":29.93}]";
var tableBBB = "[{\"securityvarietycode\":\"1000576786\",\"companycode\":\"80463417\",\"securitycode\":\"603978\",\"shares\":1000}]";
var tableTTT = "[{\"securityvarietycode\":\"1000576786\",\"srkpj\":35.92,\"srspj\":43.1,\"srzdf\":44.0027,\"srhsl\":0.06}]";
var tableEEE = "[{\"secucode\":\"603978\",\"tdate\":\"2017-08-07T00:00:00\",\"high\":43.1},{\"secucode\":\"603978\",\"tdate\":\"2017-08-08T00:00:00\",\"high\":47.41}]";
var tableMMM = "[]";
var tableJJJ = "[{\"secucode\":\"603978\",\"tdate\":\"2017-08-07T00:00:00\",\"avgprice\":42.82},{\"secucode\":\"603978\",\"tdate\":\"2017-08-08T00:00:00\",\"avgprice\":47.41}]";
var tableNNN = "[{\"secucode\":\"603978\",\"tdate\":\"2017-08-07T00:00:00\",\"high\":43.1},{\"secucode\":\"603978\",\"tdate\":\"2017-08-08T00:00:00\",\"high\":47.41}]"; var tableA = JsonConvert.DeserializeObject<List<TableA>>(tableAAA);
var tableB = JsonConvert.DeserializeObject<List<TableB>>(tableBBB);
var tableT = JsonConvert.DeserializeObject<List<TableT>>(tableTTT);
var tableE = JsonConvert.DeserializeObject<List<TableE>>(tableEEE);
var tableM = JsonConvert.DeserializeObject<List<TableM>>(tableMMM);
var tableJ = JsonConvert.DeserializeObject<List<TableJ>>(tableJJJ);
var tableN = JsonConvert.DeserializeObject<List<TableE>>(tableNNN); var query = from a in tableA
join b in tableB on a.companycode equals b.companycode into ab
from def_b in ab.DefaultIfEmpty(new TableB())
join t in tableT on def_b.securityvarietycode equals t.securityvarietycode into bt
join e in tableE on a.listingdate equals e.tdate into ae
join m in tableM on a.securitycode equals m.securitycode into am
from def_m in am.DefaultIfEmpty(new TableM())
join j in tableJ on def_m.tdatep equals j.tdate into mj
join n in tableN on def_m.tdatep equals n.tdate into mn
from def_t in bt.DefaultIfEmpty(new TableT())
from def_e in ae.DefaultIfEmpty(new TableE())
from def_j in mj.DefaultIfEmpty(new TableJ())
orderby def_m.tdatep
select new Result
{
listingopen = def_t.srkpj,
listingclose = def_t.srspj,
listingopenpremium = Math.Round((def_t.srkpj / a.issueprice - ) * , ),
listingchg = def_t.srzdf,
listingturnover = def_t.srhsl,
listinghighpchg = Math.Round((def_e.high / a.issueprice - ) * , ),
opendate = def_m.tdatep,
highpchg = 0d, //api层处理,
limitupdays = def_m.days,
listingavg = def_j.avgprice,
profit = (def_j.avgprice - a.issueprice) * def_b.shares,//api层处理,
issuePrice = a.issueprice,//用于api层处理
shares = def_b.shares,//用于api层处理
}; var list = query.ToList(); Console.WriteLine(JsonConvert.SerializeObject(list));
Console.ReadKey();
} #region Class
private class TableA
{
public string companycode { get; set; }
public string securitycode { get; set; }
public string securityshortname { get; set; }
public string financecode { get; set; }
public DateTime purchasedate { get; set; }
public DateTime listingdate { get; set; }
public double issueprice { get; set; }
}
private class TableB
{
public string securityvarietycode { get; set; }
public string companycode { get; set; }
public string securitycode { get; set; }
public int shares { get; set; }
} private class TableE
{
public string secucode { get; set; }
public DateTime tdate { get; set; }
public double high { get; set; }
}
private class TableJ
{
public string secucode { get; set; }
public DateTime tdate { get; set; }
public double avgprice { get; set; }
}
private class TableM
{
public string securitycode { get; set; }
public DateTime tdatep { get; set; }
public int days { get; set; }
}
private class TableT
{
public string securityvarietycode { get; set; }
public double srkpj { get; set; }
public double srspj { get; set; }
public double srzdf { get; set; }
public double srhsl { get; set; }
}
private class Result
{
public double listingopen { get; set; }
public double listingclose { get; set; }
public double listingopenpremium { get; set; }
public double listingchg { get; set; }
public double listingturnover { get; set; }
public double listinghighpchg { get; set; }
public DateTime opendate { get; set; }
public double highpchg { get; set; }
public int limitupdays { get; set; }
public double listingavg { get; set; }
public double profit { get; set; }
public double issuePrice { get; set; }
public int shares { get; set; }
} #endregion } }

Linq中left join之多表查询的更多相关文章

  1. springboot中使用JOIN实现关联表查询

    * 首先要确保你的表和想要关联的表有外键连接 repository中添加接口JpaSpecificationExecutor<?>,就可以使用springboot jpa 提供的API了. ...

  2. 数据库和linq中的 join(连接)操作

    sql中的连接 sql中的表连接有inner join,left join(left outer join),right join(right outer join),full join(full o ...

  3. 利用EF Core的Join进行多表查询

    背景 话说有这么一家子,老公养了一条狗,老婆养了一只猫. 数据库的设计 人表 宠物表 通过表可以知道,宠物通过Owner指向主人的Id. 问题来了,我要和故事开头一样,老公-狗,老婆-猫,对应起来,怎 ...

  4. thinkphp中如何是实现多表查询

    多表查询经常使用到,但如何在thinkphp中实现多表查询呢,其实有三种方法. 1 2 3 4 5 6 7 8 9 10 11 12 // 1.原生查询示例: $Model = new Model() ...

  5. 在mybatis框架中,延迟加载与连表查询的差异

    1.引子 mybatis的延迟加载,主要应用于一个实体类中有复杂数据类型的属性,包括一对一和一对多的关系(在xml中用collection.association标签标识).这个种属性往往还对应着另一 ...

  6. MySQL select join on 连表查询和自连接查询

    连表查询 JOIN ON 操作 描述 inner join 只返回匹配的值 right join 会从右表中返回所有的值, 即使左表中没有匹配 left join 会从左表中返回所有的值, 即使右表中 ...

  7. MySQL中 如何查询表名中包含某字段的表 ,查询MySql数据库架构信息:数据库,表,表字段

    --查询tablename 数据库中 以"_copy" 结尾的表 select table_name from information_schema.tables where ta ...

  8. EntityFramework 使用Linq处理内连接(inner join)、外链接(left/right outer join)、多表查询

    场景:在实际的项目中使用EntityFramework都会遇到使用Ef处理连接查询的问题,这里做一些小例子如何通过Linq语法处理内连接(inner join).外连接(left/right oute ...

  9. Linq中的group by多表多字段

    在sql中,如果有group by,那么select的字段只能包含分组内容,或者count.sum.avg这些统计字段. 但在linq里面,是:group 你想要什么字段 by 分组字段 比如: va ...

随机推荐

  1. Calendar获取当前年份、月份、日期

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Te ...

  2. SpringMVC @RequestParam和@RequestBody的区别

    问题:@Requestbody 用的时候遇到400和415错误,因为请求格式不对. @RequestBody @RequestBody能把简单json结构参数转换成实体类,如下代码: @Request ...

  3. powerdesigner 使用

    1. 首先要确保机器安装了MySql的ODBC驱动,去http://dev.mysql.com/downloads/connector/odbc/5.1.html 下载 Connector/ODBC ...

  4. SQLite3 C/C++ 开发接口简介

    SQLite3 C/C++ 开发接口简介 1.0 总览 SQLite3是SQLite一个全新的版本,它虽然是在SQLite 2.8.13的代码基础之上开发的,但是使用了和之前的版本不兼容的数据库格式和 ...

  5. day 36 关于io模型的问题 阻塞 和多路复用

    # from gevent import spawn,monkey;monkey.patch_all()# from socket import *# def server(ip,port):# se ...

  6. 2019-03-19-day014-内置函数

    昨日回顾 装饰器 对扩展开放 对修改封闭 不改变原调用方式 def a(c): def b(*args,**kwargs): c(*args,**kwargs) return b a() def a( ...

  7. Linux fdisk命令操作磁盘(添加、删除、转换分区等)

    创建分区1->查看原始分区sudo fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, ...

  8. Python学习笔记第七周

    目录: 1.静态方法 @staticmethod 2.类方法    @classmethod 3.属性方法  @property 4.类的特殊成员方法 a) __doc__表示类的描述信息 b) __ ...

  9. 【转载】 Pytorch(0)降低学习率torch.optim.lr_scheduler.ReduceLROnPlateau类

    原文地址: https://blog.csdn.net/weixin_40100431/article/details/84311430 ------------------------------- ...

  10. 创建文件夹c++

    linux #include <sys/types.h> #include <sys/stat.h> string filepath; mkdir(filepath.c_str ...