我有一张这样的桌子
childid parentid
------------------------
1 0
2 1
3 2
4 2
5 3
6 4
7 0
8 7
9 8
10 1
Run Code Online (Sandbox Code Playgroud)
如果我将childid设为5,那么parentid将为1(输出)
如果我将childid设为9,那么parentid将为7.(输出)
即根parentid为0,查询应该停在那里.
如何解决这样的查询?
请帮忙.
我需要一些帮助查询分层数据.这是单个简单的表,其中parent_id引用id,对于根条目可以为null.
create table edition (
id NUMBER(20),
parent_id NUMBER(20)
);
Run Code Online (Sandbox Code Playgroud)
对于表中的每条记录,我需要找到具有最大id的最深的孩子.如果记录没有子节点,则应返回其自己的id.我自己尝试但是在使用START WITH A.id = B.idA和B是子查询的地方失败了,看起来Oracle不允许这样的连接.
以下是示例数据:
id parent_id
----------------------
1 NULL
2 1
3 1
4 1
5 4
6 5
7 5
Run Code Online (Sandbox Code Playgroud)
和样本结果
id result
----------------------
1 7
2 2
3 3
4 7
5 7
6 6
7 7
Run Code Online (Sandbox Code Playgroud) 我有一张这样的桌子
create table public.incominglog
(
envelopeid varchar(36) default ''::character varying not null,
messagetype text default NULL::character varying,
initialenvelopeid varchar(36) default NULL::character varying,
processid varchar(36) default NULL::character varying,
logtimestamp timestamp,
customscode varchar(8),
exchtypeid integer
);
create unique index incominglog_envelopeid_uindex
on public.incominglog (envelopeid);
create unique index incominglog_initialenvelopeid_uindex
on public.incominglog (initialenvelopeid);
Run Code Online (Sandbox Code Playgroud)
我正在尝试插入这样的值
INSERT INTO
incominglog (
envelopeid,
messagetype,
initialenvelopeid,
processid,
logtimestamp,
customscode,
exchtypeid
)
VALUES
(
'ae2a2b46-ae4f-42a1-ada3-1f8f0aff7361',
'CMN.00001',
'aad06a96-667f-42c9-9196-8e0fec103d8b',
'4fed3854-e1de-42eb-b2c7-3ad714b58a9e',
'2019-04-17 14:57:54.195588',
'10210130',
'19200'
)
ON CONFLICT (initialenvelopeid)
DO update set
envelopeid = …Run Code Online (Sandbox Code Playgroud) var insInvoice = new NpgsqlCommand(
@"INSERT INTO invoice_detail(
invoice_id,
invoice_detail_id,
product_id,
qty,
price,
amount)
VALUES (
:_invoice_id,
:_invoice_detail_id,
:_product_id,
:_qty,
:_price,
:_qty * :_price)", c);
with(var p = insInvoice.Parameters)
{
p.Add("_invoice_id", NpgsqlDbType.Uuid, 0, "invoice_id");
p.Add("_invoice_detail_id", NpgsqlDbType.Uuid, 0, "invoice_detail_id");
p.Add("_product_id", NpgsqlDbType.Uuid, 0, "product_id");
p.Add("_qty", NpgsqlDbType.Integer, 0, "qty");
p.Add("_price", NpgsqlDbType.Numeric, 0, "price");
}
Run Code Online (Sandbox Code Playgroud)
kludge:
for(var p = insInvoice.Parameters; false;)
{
p.Add("_invoice_id", NpgsqlDbType.Uuid, 0, "invoice_id");
p.Add("_invoice_detail_id", NpgsqlDbType.Uuid, 0, "invoice_detail_id");
p.Add("_product_id", NpgsqlDbType.Uuid, 0, "product_id");
p.Add("_qty", NpgsqlDbType.Integer, 0, "qty");
p.Add("_price", NpgsqlDbType.Numeric, 0, "price");
}
Run Code Online (Sandbox Code Playgroud) 试着这样做:
SELECT CASE WHEN field = true THEN one * another ELSE one END as case_field
FROM table WHERE case_field >= 9000
Run Code Online (Sandbox Code Playgroud)
并收到case_field不存在的错误.
是否可以在不重复CASE的情况下执行此操作?
我正在努力实现:
select StoreId, StoreName from Store where StoreId in (
select StoreId from Employee where EmployeeName = 'Steve Jobs')
Run Code Online (Sandbox Code Playgroud)
我有这个代码:
public class Store
{
public virtual int StoreId { get; private set; }
public virtual string StoreName { get; set; }
public virtual IList<Employee> Staff { get; set; }
}
public class Employee
{
public virtual Store Store { get; set; }
public virtual int EmployeeId { get; private set; }
public virtual string EmployeeName { get; set; }
} …Run Code Online (Sandbox Code Playgroud) 是否可以声明方法的返回类型,例如IList小于您在内部定义的方法,例如List?它会编译运行吗?
protected static IList<String> GetJobFiles(String folder, String fileExtension)
{
List<String> jobFiles = new List<String>();
if (System.IO.Directory.Exists(folder))
{
string[] files = Directory.GetFiles(folder, fileExtension);
// Check if for matching files
if (files.Length > 0)
{
// add the files to our list collection
jobFiles.AddRange(files);
}
}
return jobFiles;
}
Run Code Online (Sandbox Code Playgroud) 这个学期在大学我有一个名为Data Structures的课程,教授允许学生选择他们喜欢的语言.因为我想成为一名游戏程序员,而且我不能再使用Java了,所以我选择了C++ ......但是现在我因为缺乏这种语言的知识而陷入困境.我必须做以下事情:创建一个SuperArray,它就像一个Delphi数组(你可以选择它的起始和结束索引).我的代码如下:
main.cpp中
#include <iostream>
#include "SuperArray.h"
using namespace std;
int main(int argc, char** argv)
{
int start, end;
cout << "Starting index" << endl;
cin >> start;
cout << "Ending index:" << endl;
cin >> end;
SuperArray array = new SuperArray(start,end);
}
Run Code Online (Sandbox Code Playgroud)
superarray.h
#ifndef _SUPERARRAY_H
#define _SUPERARRAY_H
class SuperArray
{
public:
SuperArray(int start, int end);
void add(int index,int value);
int get(int index);
int getLength();
private:
int start, end, length;
int *array;
};
#endif /* _SUPERARRAY_H */
Run Code Online (Sandbox Code Playgroud)
superarray.cpp
#include …Run Code Online (Sandbox Code Playgroud) 如何转换这个NHibernate HQL(工程)......
static IList<Phone> PhoneList()
{
ISession session = OpenSession();
IQuery query = session.CreateQuery("from Phone p where p.Kontact.ContactName = :_contact_name");
query.SetParameter("_contact_name", "lennon");
IList<Phone> contacts = query.List<Phone>();
return contacts;
}
Run Code Online (Sandbox Code Playgroud)
...到Linq-to-NHibernate(不工作):
static IList<Phone> PhoneListUsingLinq()
{
string contactName = "lennon";
ISession session = OpenSession();
var contacts = from Phone p in session.Query<Phone>()
where p.Kontact.ContactName == contactName
select p;
return contacts.ToList();
}
Run Code Online (Sandbox Code Playgroud)
对象:
public class Contact
{
public virtual int ContactId { get; set; }
public virtual string ContactName { get; set; } …Run Code Online (Sandbox Code Playgroud) 如果使用带有子查询的select case语句将else语句改为单个查询,我需要更改以下过程...
if((select COUNT(*) from pseb.dbo.meterattributedetails where meterid=@meterid)=0)
select @emf=EMF from pseb.dbo.METERMASTER where MeterID=@meterid
else if((select COUNT(*) from pseb.dbo.meterattributedetails where meterid=@meterid and dateadd(day,1,@fromdate)<DateTime)>0)
select top 1 @emf=oldvalue from pseb.dbo.meterattributedetails where MeterID=@meterid and dateadd(day,1,@fromdate)<datetime order by DateTime
else
select top 1 @emf=newvalue from pseb.dbo.meterattributedetails where meterid=@meterid and DateTime<@fromdate order by DateTime desc
Run Code Online (Sandbox Code Playgroud)
meterattribute表结构如下:
AttributeID AttributeName Oldvalue newvalue DateTime meterid
1 EMF 2.00000 4.00000 2012-07-05 4756
1 EMF 4.00000 6.00000 2012-07-10 4756
1 EMF 6.00000 8.00000 2012-07-15 4756
1 EMF 8.00000 10.00000 …Run Code Online (Sandbox Code Playgroud) c# ×4
sql ×3
nhibernate ×2
postgresql ×2
.net ×1
c#-2.0 ×1
c++ ×1
case ×1
connect-by ×1
mingw32 ×1
nhibernate-3 ×1
oracle ×1
oracle11g ×1
sql-server ×1
subquery ×1
upsert ×1