nebula语句NGQL学习笔记

引用点的属性
起始点举例 $^.<tag_name>.<prop_name>
	
		    参数        	 说明
		    $^	             起始点
		    tag_name	     点的 Tag 名称
		    prop_name	     Tag 内的属性名称
目的点举例 $$.<tag_name>.<prop_name>
	
		    参数	         说明
		    $$	             目的点
		    tag_name	     点的 Tag 名称
		    prop_name	     Tag 内的属性名称
上层返回点  $.-
		


查某个点
	match (v) where id(v) == 7711765111338858336 return v;
	
	FETCH PROP ON Mdp_User_Basic_Information 7711765111338858336 yield Mdp_User_Basic_Information.phone,Mdp_User_Basic_Information.create_time
	
	GO FROM 111 OVER follow;  从111出发查询follow边所有指向的点
	
	GO FROM 100 OVER follow WHERE $$.player.age>35 YIELD $$player.name AS teammate ,$$player.age AS Age;    $$表示目标点


创建tag
	CREATE TAG IF NOT EXISTS Mdp_User_Basic_Information(phone string NOT NULL,idcard string ,gender int,native_province int,native_city int,
	resident_province int,resident_city int,create_time datetime );
	

创建索引
	create tag index if not exists Mdp_User_Basic_Information_Index on Mdp_User_Basic_Information(phone(11),idcard(20) ,gender,native_province,native_city,resident_province ,resident_city ,create_time(19))
	
	
插入多个标签
	INSERT VERTEX test1(name), test2(age)  VALUES 199:("ZHANGSAN",22)
	
	
匹配点
	MATCH (v)  WHERE id(v) == 'player101'    RETURN v;
   LOOKUP ON supplier_product_name_tag [where]  YIELD id(vertex); 

匹配点属性
	MATCH (v:player) WHERE v.player.name == "Tim Duncan" RETURN v;
	
	MATCH (v:player{name:"Tim Duncan"})  RETURN v;
	
匹配连接的点
	在 nGQL 1.x 中,--符号用于行内注释,从 nGQL 2.x 起,--符号表示出边或入边,不再用于注释。
	MATCH (v:player{name:"Tim Duncan"})--(v2:player)   RETURN v2.player.name AS Name;
	
	用户可以在--符号上增加<或>符号指定边的方向。
	# -->表示边从 v 开始,指向 v2。对于点 v 来说是出边,对于点 v2 来说是入边。
	MATCH (v:player{name:"Tim Duncan"})-->(v2:player) RETURN v2.player.name AS Name;

	如果需要判断目标点,可以使用CASE表达式。
	nebula> MATCH (v:player{name:"Tim Duncan"})--(v2) \
        RETURN \
        CASE WHEN v2.team.name IS NOT NULL \
        THEN v2.team.name  \
        WHEN v2.player.name IS NOT NULL \
        THEN v2.player.name END AS Name;
	
	如果需要扩展模式,可以增加更多点和边。
	MATCH (v:player{name:"Tim Duncan"})-->(v2)<--(v3) RETURN v3.player.name AS Name;
	如果不需要引用点,可以省略括号中表示点的变量。
	MATCH (v:player{name:"Tim Duncan"})-->()<--(v3) RETURN v3.player.name AS Name;

匹配路径
	连接起来的点和边构成了路径。用户可以使用自定义变量命名路径。
	MATCH p=(v:player{name:"Tim Duncan"})-->(v2)  RETURN p;     点边点的结构
	+--------------------------------------------------------------------------------------------------------------------------------------+
	| p                                                                                                                                    |
	+--------------------------------------------------------------------------------------------------------------------------------------+
	| <("player100" :player{age: 42, name: "Tim Duncan"})-[:serve@0 {end_year: 2016, start_year: 1997}]->("team204" :team{name: "Spurs"})> |
	| <("player100" :player{age: 42, name: "Tim Duncan"})-[:follow@0 {degree: 95}]->("player101" :player{age: 36, name: "Tony Parker"})>   |
	| <("player100" :player{age: 42, name: "Tim Duncan"})-[:follow@0 {degree: 95}]->("player125" :player{age: 41, name: "Manu Ginobili"})> |
	+--------------------------------------------------------------------------------------------------------------------------------------+
	
创建图空间
	CREATE SPACE IF NOT EXISTS test_zla (partition_num=1, replica_factor=1, vid_type=int) comment="测试图空间";
	
创建边
	CREATE EDGE IF NOT EXISTS supplier_product_info(company_name string,product_name string, factory_name string, product_status int, data_date timestamp) 
	插入数据	INSERT EDGE supplier_product_info (company_name,product_name,factory_name,product_status) VALUES 10->11@:("n1", "a13","a14",1);
创建边的索引
	CREATE EDGE INDEX IF NOT EXISTS supplier_product_info_index on supplier_product_info(company_name(10));

重构索引
	REBUILD EDGE INDEX supplier_product_info_index;
	
	
查找边
LOOKUP ON supplier_product_info YIELD edge AS e;
LOOKUP ON supplier_product_info where supplier_product_info.product_name=='副驾驶员座椅' and supplier_product_info.product_status==0 YIELD edge AS e;


统计点边数量
SUBMIT JOB STATS
SHOW STATS


排序的用法
match (src:supplier_id_tag)-[r:SUPPLIER_STOP_DUMP]->()
return src, properties(src).company_name ,r.happen_data,r.stop_line_length,r.uncouple_the_numbers as a order by a desc



获取指定点的出度(或者入度)?
	一个点的“出度”是指从该点出发的“边”的条数。入度,是指指向该点的边的条数。
	nebula > MATCH (s)-[e]->() WHERE id(s) == "given" RETURN count(e); #出度
	nebula > MATCH (s)<-[e]-() WHERE id(s) == "given" RETURN count(e); #入度
	因为没有对出度和入度的进行特殊处理(例如索引或者缓存),这是一个较慢的操作。特别当遇到超级节点时,可能会发生OOM。

是否有办法快速获取“所有”点的出度和入度?
	没有直接命令。可以使用 Nebula Algorithm。

悬挂边¶
	悬挂边 (Dangling edge) 是指一条起点或者终点不存在于数据库中的边。
	在 Nebula Graph 3.1.0中,有两种情况可能会出现悬挂边。
	第一种情况:在起点和终点插入之前,用 INSERT EDGE 语句插入一条边。
	第二种情况:使用 DELETE VERTEX 语句删除点的时候,没有使用WITH EDGE选项。此时系统默认不删除该点关联的出边和入边,这些边将变成悬挂边。
	Nebula Graph 3.1.0 的数据模型中,由于设计允许图中存在“悬挂边”;没有 openCypher 中的 MERGE 语句。对于悬挂边的保证完全依赖应用层面。用户可以使用 GO 和 LOOKUP 语句查询到悬挂边,但无法使用 MATCH 语句查询到悬挂边。
悬挂边有其中一个点不存在就是悬挂边,所以在判断的时候可以  match(v) where id(v)== -8168681291272244276 or id(v)==-3603440618198293890 return count(v),查边的两个点,结果等于2就代表不是悬挂边

当count=1时代表两个点及边存在
	MATCH (a)-[e:SUPPLIER_FREE_REPAIR]->(b) where id(a)== -8168681291272244276 and id(b)== -8168681291272244276 and rank(e)==-8923431504592279960 RETURN count(e)

新建tag

create tag test(name);
insert vertex if not exists test(name) values 
"销售订单":(销售订单), 
"物流订单":(), 
"生产订单":(), 
"财务订单":(), 
"订单":(), 
"BOM":(), 
"产品":(), 
"零部件":(), 
"竞品车":(), 
"用户":(), 
"经销商":(), 
"政企":(), 
"门店":(), 
"车辆":(), 
"生产":(), 
"发运":(), 
"行驶":(), 
"服务":(), 
"合同":(), 
"生产合同":(), 
"采购合同":(), 
"销售合同":(), 
"一元化":();


新建没有属性的边
create edge edgedingdan();
create edge edgedbom();
create edge edgeyonghu();
create edge edgecheliang();
create edge edgehetong();
create edge edgeyiyuanhua();

插入边
insert edge if not exists edgedingdan() values 
"财务订单"->"订单":(),
"生产订单"->"订单":(),
"物流订单"->"订单":(),
"销售订单"->"订单":();

insert edge if not exists edgedbom() values 
"产品"->"BOM":(),
"零部件"->"BOM":(),
"竞品车"->"BOM":();

insert edge if not exists edgeyonghu() values 
"经销商"->"用户":(),
"政企"->"用户":(),
"门店"->"用户":();


insert edge if not exists edgecheliang() values 
"生产"->"车辆":(),
"发运"->"车辆":(),
"行驶"->"车辆":(),
"服务"->"车辆":();


insert edge if not exists edgehetong() values 
"生产合同"->"合同":(),
"采购合同"->"合同":(),
"销售合同"->"合同":();

insert edge if not exists edgeyiyuanhua() values 
"订单"->"一元化":(),
"BOM"->"一元化":(),
"用户"->"一元化":(),
"合同"->"一元化":(),
"车辆"->"一元化":();




    **查询产品信息**  
    `company_name`   string  comment '供应商名称'
    `product_name`   string  comment '产品名称'
    `factory_name`   string  comment '生产工厂名称'
    `product_status`   int64  comment '产品状态 0潜在、1潜在合作、2合作'
    
    match (src:supplier_id_tag)-[r:SUPPLIER_PRODUCT_INFO]->()
    return id(src), properties(src).company_name ,r.product_name,r.factory_name,r.product_status
     
    **查询配套履历**  
    `supporting_vehicle_enterprise_name`   string  comment '配套车企名称'
    `product_name`   string  comment '产品名称'
    `start_supply_year`   string  comment '开始供货年份'
    `supply_amount`   string  comment '上年度供货额'
    `sale_percent`   string  comment '销售额占比'
    `main_supporting_model`   string  comment '主要配套车型'

    match (src:supplier_id_tag)-[r:SUPPLIER_SUPPORTING_RESUME]->()
    return id(src), properties(src).company_name ,r.supporting_vehicle_enterprise_name,r.product_name,r.start_supply_year,r.supply_amount,r.sale_percent,r.main_supporting_model
  
             
    **查询主要人员**
    `name`   string  comment '姓名'
    `job`   string  comment '职务'
    
    match (src:supplier_id_tag)-[r:SUPPLIER_MAIN_STAFF]->()
    return id(src), properties(src).company_name ,r.name,r.job
      
      
     go from hash('EID21638492') over  SUPPLIER_MAIN_STAFF  
     yield 
     $^.supplier_id_tag.company_name  as company_name
     ,SUPPLIER_MAIN_STAFF.name as  name 
      ,SUPPLIER_MAIN_STAFF.job as job
      ,case  SUPPLIER_MAIN_STAFF.job 
      when '董事长' then 1 
      when '总经理/总裁' then 2 
      when '销售部长' then 3 
      when '技术部长/总监' then 4 
      when '质量部长/总监' then 5 
      when '物流部长/总监' then 6
      when '财务部长/总监' then 7
      when '销售负责人' then 8
      else 9 end as order_rank
      | order by $-.order_rank asc
      
    **查询未来新技术**
     `product_name`   string  comment '产品名称'
     
    match (src:supplier_id_tag)-[r:SUPPLIER_FUTURE_TECHNICAL]->()
    return id(src), properties(src).company_name ,r.product_name
    
    
    go from hash('EID21192510') over SUPPLIER_FUTURE_TECHNICAL 
    yield  $^.supplier_id_tag.company_name  as company_name
    ,SUPPLIER_FUTURE_TECHNICAL.product_name
  
  
    **查询签署合同**     展示的是该供应商签署的所有合同类型 todo查询语句是否需要聚合成集合返回
    `contract_type_name`   string  comment '合同类型名称'
    `contract_name`   string  comment '合同名称'
    `contract_no`   string  comment '合同编码'
    `start_time`   string  comment '起始时间'
    `end_time`   string  comment '有效截止日期'

    match (src:supplier_id_tag)-[r:SUPPLIER_CERTIFICATION]->()
    return  id(src), properties(src).company_name, r.contract_type_name ,r.contract_name,r.contract_no,r.start_time,r.end_time

    **交付表现**
     `evaluation_unit`   string  comment '提出部门'
     `evaluation_module_name`   string  comment '扣分模块'
     `happen_month`   string  comment '月度'
     `month_deduct_marks`   double  comment '月问题分值'
     `happen_year`   string  comment '年度'

       整体表现
     go from hash('EID21128313') over  SUPPLIER_PAY_PERFORMANCE  where SUPPLIER_PAY_PERFORMANCE.happen_year == '2022' 
            yield 
            distinct
            $$.supplier_id_tag.company_name  as company_name
            ,SUPPLIER_PAY_PERFORMANCE.evaluation_module_name as  evaluation_module_name 
              ,SUPPLIER_PAY_PERFORMANCE.evaluation_unit as  evaluation_unit 
             ,SUPPLIER_PAY_PERFORMANCE.happen_year as happen_year
            ,SUPPLIER_PAY_PERFORMANCE.happen_month as happen_month
            ,SUPPLIER_PAY_PERFORMANCE.month_deduct_marks as month_deduct_marks
             |yield
            $-.company_name as company_name
            ,$-.evaluation_module_name as evaluation_module_name
            ,$-.happen_year as happen_year
             ,$-.happen_month as happen_month
             ,sum($-.month_deduct_marks) as month_deduct_marks
            |order by $-.evaluation_module_name asc ,$-.happen_month asc
    各模块表现
     go from hash('EID21932461') over  SUPPLIER_PAY_PERFORMANCE  where SUPPLIER_PAY_PERFORMANCE.happen_year == '2022'  and SUPPLIER_PAY_PERFORMANCE.evaluation_module_name == '开发'
                yield 
                distinct
                $^.supplier_id_tag.company_name  as company_name
                ,SUPPLIER_PAY_PERFORMANCE.evaluation_module_name as  evaluation_module_name 
                ,SUPPLIER_PAY_PERFORMANCE.happen_year as happen_year
                 ,SUPPLIER_PAY_PERFORMANCE.evaluation_unit as evaluation_unit
                ,SUPPLIER_PAY_PERFORMANCE.happen_month as happen_month
                ,SUPPLIER_PAY_PERFORMANCE.month_deduct_marks as month_deduct_marks
                 |yield
                $-.company_name as company_name
                , $-.evaluation_unit as evaluation_unit
                ,$-.evaluation_module_name as evaluation_module_name
               ,$-.happen_month as happen_month
                ,$-.happen_year as happen_year
                 ,$-.month_deduct_marks as month_deduct_marks
                |order by $-.happen_month asc
                
      
    **供应商给的供货额**
    `statistics_time`   string  comment '统计时间'
    ,`parts_name`   string  comment '零部件名称', 
    `supply_amount`   double  comment '供货额'

    match (src:supplier_id_tag)-[r:SUPPLIER_SUPPLY_AMOUNT_FOR_GWM]->()
    return id(src), properties(src).company_name ,r.statistics_time,r.supply_amount

    
    供应商给的供货额
    占比
   go from hash('EID21638492') over  SUPPLIER_SUPPLY_AMOUNT_FOR_GWM ,SUPPLIER_PROFIT_EDGE 
     where substr(SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.statistics_time,0,4) >= '2019' //入参 string 开始年份
      and substr(SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.statistics_time,0,4) <= '2022' //入参 string 结束年份
      or ( substr(SUPPLIER_PROFIT_EDGE.profit_date,0,4) >= '2019' and  substr(SUPPLIER_PROFIT_EDGE.profit_date,0,4) <= '2022' )//入参 string '2019':开始年份,'2022':结束年份
        yield 
        $$.supplier_id_tag.company_name as material_name
        ,SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.supply_amount as  supply_amount 
        ,substr(SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.statistics_time,0,4) as  statistics_time 
        ,SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.parts_name as  parts_name 
        ,substr(SUPPLIER_PROFIT_EDGE.profit_date,0,4) as `year` 
        ,SUPPLIER_PROFIT_EDGE.profit_business_income  as business_income 
        |yield case when $-.statistics_time is null or  $-.statistics_time is empty  then $-.year else $-.statistics_time end as statistics_time //将年份补齐 供货年份  
        ,case when $-.supply_amount is null or  $-.supply_amount is empty then 0 else  $-.supply_amount end  as supply_amount //用0代替空值
        , case when $-.year is null or  $-.year is empty  then $-.statistics_time else $-.year end as year //将年份补齐 营业年份
        ,case when $-.business_income is null or  $-.business_income is empty then 0 else  $-.business_income end as business_income  //用0代替控制  
        |yield  $-.statistics_time  as statistics_time
        ,sum($-.supply_amount) as supply_amount // 求和
        , $-.year  as year
        ,sum($-.business_income)  as business_income //求和
        |yield  $-.statistics_time  as statistics_time // string 年
          , case when $-.supply_amount == 0 or $-.business_income == 0 then 0 else ($-.supply_amount / $-.business_income) end as rate //double 供货 营收比例  分子分母为零时比值都为零
          ,$-.supply_amount as  supply_amount     // double 供货额 
          ,$-.business_income as business_income   // double 营业收入
       
       //年维度
        go from hash('EID21000114') over  SUPPLIER_SUPPLY_AMOUNT_FOR_GWM  
        where substr(SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.statistics_time,0,4) >= '2021' //入参 string 开始年份
       and substr(SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.statistics_time,0,4) <= '2022' //入参 string 结束年份
         yield 
         $$.supplier_id_tag.company_name as material_name
         ,SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.supply_amount as  supply_amount 
         ,SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.statistics_time as  statistics_time 
         ,SUPPLIER_SUPPLY_AMOUNT_FOR_GWM.parts_name as  parts_name 
         | yield 
         $-.material_name    as material_name   //出参供应商名称 string
         ,substr($-.statistics_time,0,4) as year //出参 年 string
         ,sum(toFloat($-.supply_amount)) as supply_amount  //出参 年供货额  Long
         |order by $-.year asc
    **停线甩车**
    `happen_data`   string  comment '发生日期'
    `stop_line_length`   int64  comment '停线时长'
    `uncouple_the_numbers`   int64  comment '甩车台数'

    match (src:supplier_id_tag)-[r:SUPPLIER_STOP_DUMP]->()
    return  id(src),properties(src).company_name ,r.happen_data,r.stop_line_length,r.uncouple_the_numbers

    go from hash('EID21638492') over  SUPPLIER_STOP_DUMP  where substr(SUPPLIER_STOP_DUMP.happen_data,0,4) == '2022'  // string 入参 '2021':需要查询的年度
    yield 
    $$.supplier_id_tag.company_name 
    ,SUPPLIER_STOP_DUMP.happen_data as  happen_data 
    ,SUPPLIER_STOP_DUMP.uncouple_the_numbers as uncouple_the_numbers
    ,SUPPLIER_STOP_DUMP.stop_line_length as  stop_line_length 


    **产能能力**
    `factory_name`   string  comment '工厂名称'
    `product_name`   string  comment '产品名称'
    `product_code`   string  comment '产品编码'
    `standard_product_capacity`   double  comment '标准产能(万件)'
    `max_product_capacity`   double  comment '年最大产能(万件)'
    `pre_product`   double  comment '预计生产量(万件)'
    `line_body_no`   double  comment '涉及线体数量(条)'
    `average_product_beat`   double  comment '单件平均生产节拍(秒)'

    match (src:supplier_id_tag)-[r:SUPPLIER_CAPACITY]->()
    return id(src), properties(src).company_name ,r.factory_name,r.product_name,r.product_code,r.standard_product_capacity,r.max_product_capacity,r.pre_product,r.line_body_no,r.average_product_beat
     
     
    go from hash('EID21192510') over SUPPLIER_CAPACITY 
    yield  $^.supplier_id_tag.company_name  as company_name
    ,SUPPLIER_CAPACITY.factory_name
    ,SUPPLIER_CAPACITY.product_name
    ,SUPPLIER_CAPACITY.product_code
    ,SUPPLIER_CAPACITY.standard_product_capacity
    ,SUPPLIER_CAPACITY.max_product_capacity
     ,SUPPLIER_CAPACITY.pre_product
      ,SUPPLIER_CAPACITY.line_body_no
      ,SUPPLIER_CAPACITY.average_product_beat
      
    **12个月无偿维修达成**
     `stat_month`   string  comment '统计月'
     `supplier_short_name`   string  comment '供应商简称'
     `supplier_full_name`   string  comment '供应商全称'
     `repair_rate`   int64  comment '12个月无偿维修达成'

     go from hash('EID21000114') over  SUPPLIER_FREE_REPAIR  where substr(SUPPLIER_FREE_REPAIR.stat_month,0,4) == '2022' 
      yield 
      $$.supplier_id_tag.company_name as company_name
      ,SUPPLIER_FREE_REPAIR.stat_month as  stat_month 
      ,SUPPLIER_FREE_REPAIR.supplier_short_name as  supplier_short_name 
      ,SUPPLIER_FREE_REPAIR.supplier_full_name as  supplier_full_name 
      ,SUPPLIER_FREE_REPAIR.repair_rate as  repair_rate 
      |order by $-.stat_month asc
 
    **竞争对手**
    `part_name`   string  comment '零部件名称'
    `part_code`   string  comment '零部件编码'
    `competitor_code`   string  comment '竞争对手编码'
    `competitor_name`   string  comment '竞争对手名称'
    `competitor_id`   string  comment '竞争对手id'
    
    match (src:supplier_id_tag)-[r:SUPPLIER_COMPETITOR]->()
    return id(src), properties(src).company_name ,r.part_name,r.part_code,r.competitor_code,r.competitor_name,r.competitor_id

     go from -3810239706588197157 over  SUPPLIER_COMPETITOR  where SUPPLIER_COMPETITOR.part_name == '非金属嵌件六角法兰面锁紧螺母'   //入参 `part_code`   string类型  comment '零部件编码'
        yield 
        distinct
        SUPPLIER_COMPETITOR.part_name as  part_name 
        ,SUPPLIER_COMPETITOR.competitor_code as  competitor_code 
        ,SUPPLIER_COMPETITOR.competitor_name as  competitor_name 
        ,SUPPLIER_COMPETITOR.competitor_id as  competitor_id 
        
        go from -3810239706588197157 over  SUPPLIER_COMPETITOR  
             yield 
            distinct
            SUPPLIER_COMPETITOR.part_name as  part_name 
            

    go from -3810239706588197157 over  SUPPLIER_COMPETITOR  where SUPPLIER_COMPETITOR.part_code == 'Q33806F3E'   //入参 `part_code`   string类型  comment '零部件编码'
    yield 
    SUPPLIER_COMPETITOR.part_name as  part_name 
    ,SUPPLIER_COMPETITOR.part_code as  part_code 
    ,SUPPLIER_COMPETITOR.competitor_code as  competitor_code 
    ,SUPPLIER_COMPETITOR.competitor_name as  competitor_name 
    ,SUPPLIER_COMPETITOR.competitor_id as  competitor_id 
    
    
    //返回零部件编码和名称
    go from -3810239706588197157 over  SUPPLIER_COMPETITOR   
        yield 
        distinct
        SUPPLIER_COMPETITOR.part_name as  part_name 
        ,SUPPLIER_COMPETITOR.part_code as  part_code 
        
 
    **滚动年度绩效表现**
     `monthly_grade`   string  comment '月度等级'
     `happen_month`   string  comment '发生月份(yyyy-mm)'
     
     match (src:supplier_id_tag)-[r:SUPPLIER_YEARS_PERFORMANCE]->()
     return id(src), properties(src).company_name ,r.monthly_grade,r.happen_month

    go from hash('EID21000114') over  SUPPLIER_YEARS_PERFORMANCE  
      where SUPPLIER_YEARS_PERFORMANCE.happen_month >= '2021-08' //入参 string 开始年份-月份
      and SUPPLIER_YEARS_PERFORMANCE.happen_month <= '2022-08' //入参 string 结束年份-月份
        yield 
        $$.supplier_id_tag.company_name as material_name   //出参供应商名称 string
        ,SUPPLIER_YEARS_PERFORMANCE.monthly_grade as  monthly_grade //出参 供应商等级 int
        ,SUPPLIER_YEARS_PERFORMANCE.happen_month as  happen_month //出参 年-月 string
          |order by $-.happen_month asc

    **供货产品**
    `part_code`   string  comment '零件号'
    `part_name`   string  comment '零件名'
    `entry_code`   string  comment '项目编码'
    `competing_model`   string  comment '竞品车'
    `supply_base`   string  comment '供货基地'
    `factory_name`   string  comment '生产基地'
    `product_single_price`   string  comment '产品单价(元)'
 
     match (src:supplier_id_tag)-[r:SUPPLIER_SUPPLY_PRODUCTS]->()
     return id(src), properties(src).company_name ,r.part_code,r.part_name,r.entry_code,r.competing_model,r.supply_base,r.factory_name,r.product_single_price
        
         供货产品模型  go from hash('EID21644196') over  SUPPLIER_SUPPLY_PRODUCTS  
            yield 
            distinct
            $$.supplier_id_tag.company_name as material_name  //出参 供应商名称 string
            ,SUPPLIER_SUPPLY_PRODUCTS.part_code as  part_code //出参 零部件编码 string
            ,SUPPLIER_SUPPLY_PRODUCTS.part_name as  part_name //出参 零部件名称 string

    **平均报价周期**
     `four_level_name`   string  comment '四级分类名称'
     `start_time`   string  comment '询价开始时间'
     `push_time`   string  comment '询价结束时间'
     match (src:supplier_id_tag)-[r:SUPPLIER_AVERAGE_QUOTA]->()
     return id(src), properties(src).company_name ,r.four_level_name,r.start_time,r.push_time,r.month_quote_cycle,r.quarter_quote_cycle

    月度报价周期
        go from hash('EID21000114') over  SUPPLIER_AVERAGE_QUOTA  
            where substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,7) >= '2021-08' //入参 string 开始年份-月份
            and substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,7) <= '2022-08' //入参 string 结束年份-月份
              yield 
              distinct
              $$.supplier_id_tag.company_name as material_name
              ,SUPPLIER_AVERAGE_QUOTA.four_level_name as  four_level_name 
              ,SUPPLIER_AVERAGE_QUOTA.start_time as  start_time 
              ,SUPPLIER_AVERAGE_QUOTA.quote_cycle as  quote_cycle 
              ,SUPPLIER_AVERAGE_QUOTA.push_time as  push_time 
              | yield 
              $-.material_name    as material_name   //出参供应商名称 string
              ,substr($-.start_time,0,7) as mon //出参 年-月 string
              ,avg(toFloat($-.quote_cycle)) as month_quote_cycle  //出参 月平均报价周期  int
              |order by $-.mon asc
        
        季度报价周期
          go from hash('EID21638492') over  SUPPLIER_AVERAGE_QUOTA  
           where substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,7) >= '2021-08' //入参 string 开始年份-月份
           and substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,7) <= '2022-08' //入参 string 结束年份-月份
             yield 
             distinct
              $$.supplier_id_tag.company_name as material_name
             ,SUPPLIER_AVERAGE_QUOTA.four_level_name as  four_level_name 
             ,SUPPLIER_AVERAGE_QUOTA.start_time as  start_time 
             ,SUPPLIER_AVERAGE_QUOTA.quote_cycle as  quote_cycle 
             ,SUPPLIER_AVERAGE_QUOTA.push_time as  push_time 
           ,substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,5) as year
             ,floor(toInteger(substr(SUPPLIER_AVERAGE_QUOTA.start_time,5,2))/3.1)+1 as quote
             | yield 
             $-.material_name    as material_name  //出参供应商名称 string
             ,$-.year+$-.quote as quote //出参 年-季度 string
             ,avg(toFloat($-.quote_cycle)) as quarter_quote_cycle  //季度报价周期  int
             |order by $-.quote asc
        
        年度报价周期
          go from 891650722852766578 over  SUPPLIER_AVERAGE_QUOTA  
            where substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,4) >= '2021' //入参 string 开始年份
            and substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,4) <= '2022' //入参 string 结束年份
              yield 
              distinct
              $$.supplier_id_tag.company_name as material_name
                  ,SUPPLIER_AVERAGE_QUOTA.four_level_name as  four_level_name 
                  ,SUPPLIER_AVERAGE_QUOTA.start_time as  start_time 
                  ,SUPPLIER_AVERAGE_QUOTA.quote_cycle as  quote_cycle 
                  ,SUPPLIER_AVERAGE_QUOTA.push_time as  push_time 
                  | yield 
                  $-.material_name    as material_name //出参供应商名称 string
                  ,substr($-.start_time,0,4) as year  //出参 年 string
                  ,avg(toFloat($-.quote_cycle)) as year_quote_cycle  //年度报价周期  int
                  |order by $-.year asc
        
          产品报价周期
         go from 891650722852766578 over  SUPPLIER_AVERAGE_QUOTA 
                 where substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,7) >= '2021-08' //入参 string 开始年份-月份
                 and substr(SUPPLIER_AVERAGE_QUOTA.start_time,0,7) <= '2022-08' //入参 string 结束年份-月份
                    yield 
                    distinct
                    $$.supplier_id_tag.company_name as material_name
                        ,SUPPLIER_AVERAGE_QUOTA.four_level_name as  four_level_name 
                        ,SUPPLIER_AVERAGE_QUOTA.start_time as  start_time 
                        ,SUPPLIER_AVERAGE_QUOTA.quote_cycle as  quote_cycle 
                          ,SUPPLIER_AVERAGE_QUOTA.push_time as  push_time 
                        | yield 
                        $-.material_name    as material_name //出参供应商名称 string
                        ,$-.four_level_name as four_level_name  //出参  产品名称 string
                        ,avg(toFloat($-.quote_cycle)) as quote_cycle  //出参 产品报价周期 int
    
**其他NGQL语句**

    match (src:supplier_id_tag)-[r:SUPPLIER_PAY_PERFORMANCE]->()
    return r.evaluation_unit,r.evaluation_module_name


    供应商画像查询语句  
    创建索引
    create edge index supplier_product_info_index on supplier_product_info(product_name(10))
    create edge index supplier_supporting_resume_index on supplier_supporting_resume(product_name(10))
    create edge index supplier_main_staff_index on supplier_main_staff(name(10))
    create edge index supplier_future_technical_index on supplier_future_technical(product_name(10))
    create edge index supplier_certification_index on supplier_certification(contract_type_name(10))
    create tag index supplier_id_tag_index on supplier_id_tag(company_name(10))
    重构索引
    rebuild edge index supplier_product_info_index
    rebuild edge index supplier_supporting_resume_index
    rebuild edge index supplier_main_staff_index
    rebuild edge index supplier_future_technical_index
    rebuild edge index  supplier_certification_index 
    rebuild tag index supplier_id_tag_index
    查找边
    LOOKUP ON supplier_product_info where supplier_product_info.product_name=='副驾驶员座椅' and supplier_product_info.product_status==0 YIELD edge AS e;
    
    遍历所有供应商的ID
    MATCH (v:supplier_id_tag)  RETURN id( v);
    -9198028939921843042
    -9149270261340820803
    -9073224403055198139
    -9057342775399480428
    
    查询某个供应商的配套履历
    MATCH (v:supplier_id_tag) where id(v)==-9198028939921843042 RETURN id( v)  as VertexID |go from $-.VertexID over supplier_supporting_resume 
    yield properties(edge).supplier_name 
             ,properties(edge).supporting_vehicle_enterprise_name
               ,properties(edge).product_name
               ,properties(edge).start_supply_year
               ,properties(edge).main_supporting_model
             ,properties(edge).supply_amount
               ,properties(edge).sale_percent
             
    MATCH (v:supplier_id_tag) where v.company_name=="件有限公司" RETURN id( v)  as VertexID |go from $-.VertexID over supplier_supporting_resume 
    yield properties(edge).supplier_name 
             ,properties(edge).supporting_vehicle_enterprise_name
               ,properties(edge).product_name
               ,properties(edge).start_supply_year
               ,properties(edge).main_supporting_model
             ,properties(edge).supply_amount
               ,properties(edge).sale_percent
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YiRan_Zhao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值