小编a_h*_*ame的帖子

在'附近使用正确的语法'?Reg = Reg =?'

public static void updateData(Connection con, String make, String reg) {
    String selectString = "UPDATE Cars SET Make = ? WHERE Reg = ?";
    try
    {
        PreparedStatement pStmt = con.prepareStatement(selectString);
        pStmt.setString(1, make);
        pStmt.setString(2, reg);
        pStmt.executeUpdate(selectString);
        pStmt.close();

    }...
Run Code Online (Sandbox Code Playgroud)

我为这段代码收到以下错误:

SQL Exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? WHERE Reg = ?' at line 1
Run Code Online (Sandbox Code Playgroud)

如果有人可以帮助我,我将不胜感激.我搜索过,但我的问题与我发现的解决方案完全不同.

java mysql sql

0
推荐指数
1
解决办法
191
查看次数

从 postgresql 中选择不同的查询插入表

我有一个包含 33 列的表,其中有多个重复项,因此我试图以这种方式删除所有重复项,因为此选择不同的查询具有正确的数据数量。

    CREATE TABLE students (
school char(2),sex char(1),age int,address char(1),famsize char(3),
Pstatus char(1),Medu int,Fedu int,Mjob varchar,Fjob varchar,reason varchar,
guardian varchar,traveltime int,studytime int,failures char(1),
schoolsup varchar,famsup varchar,paid varchar,activities varchar,
nursery varchar,higher varchar,internet varchar,romantic varchar,
famrel int,freetime int,goout int,Dalc int,Walc int,
health int,absences int,id serial primary key)
Run Code Online (Sandbox Code Playgroud)

我想将这个包含 8 列的 select 不同查询中的所有值插入到另一个空表中。

SELECT DISTINCT ("school","sex","age","address","famsize","Pstatus","Medu","Fedu","Mjob","Fjob","reason","nursery","internet")
FROM students;
Run Code Online (Sandbox Code Playgroud)

postgresql

0
推荐指数
1
解决办法
2762
查看次数

多部分标识符无法绑定但没有连接问题?

我在MS Server Management studio v11.02上运行以下但是'我收到一个错误说:

The multi-part identifier "PO.LastPo" could not be bound.
Run Code Online (Sandbox Code Playgroud)

我能做些什么来解决这个问题?

SELECT DISTINCT PO.LastPo
    INTO #IncludedPoll
    FROM
    (
            -- Inner query makes sure member was actually enrolled for 2 yrs
            SELECT LastPo, COUNT(*) AS Periods
            FROM [Cye].[2_output_lastPoll] PO
            WHERE PO.PollPq IN (1,2)
            GROUP BY LastPo
    ) A
    WHERE Periods IN (1,2) AND A.LastPo NOT IN (SELECT LastPo FROM #FilterPoll)
Run Code Online (Sandbox Code Playgroud)

#FilterPoll是一个临时表,我很好,并包含一些我想从#IncludedPoll临时表中过滤掉的ID .

我已经看过其他答案,但它们都与连接有关,这不应该是问题.

sql t-sql sql-server

0
推荐指数
1
解决办法
204
查看次数

我想在Oracle中将字符串20/01/2017 10:46:19 AM转换为2017-01-20 10:46:19 AM.

我想转换一个字符串,比如

20/01/2017 10:46:19 AM 
Run Code Online (Sandbox Code Playgroud)

2017-01-20 10:46:19 AM 
Run Code Online (Sandbox Code Playgroud)

在Oracle中 伙计们好吗?我尝试使用to_date和to_timestamp但它没有用!

sql oracle

0
推荐指数
1
解决办法
42
查看次数

如何在一行中获得postgreSQL中的2个最新值?

我按顺序列出了这个项目表:

orderitemid  orderid itemid quantity price      createdate
1                1     12     5     15.5         2016-12-04 11:35:02.06629
2                1     17     5     13.2         2016-12-04 11:32:02.06629
3                2     12     2     12.5         2016-12-05 11:35:02.06629
4                2     17     1     12.6         2016-12-05 11:35:02.06629
5                2     18     15    14.5         2016-12-04 11:35:02.06629
6                3     12     45     3           2015-12-04 11:35:02.06629
Run Code Online (Sandbox Code Playgroud)

我有一个查询,它给出了每个项目的最新顺序,所以:

select distinct on (itemid) *
from orderitems
order by itemid,createdate
Run Code Online (Sandbox Code Playgroud)

这给了:

orderitemid  orderid itemid quantity price      createdate
3                2     12     2     12.5         2016-12-05 11:35:02.06629
4                2     17     1     12.6         2016-12-05 …
Run Code Online (Sandbox Code Playgroud)

sql postgresql greatest-n-per-group

0
推荐指数
1
解决办法
69
查看次数

PSQL除外与全部除外

我有以下架构:

create table Took(
sID integer,
oID integer,
grade integer);



INSERT INTO Took VALUES
    (1, 1, 90),
    (1, 2, 100),
    (2, 1, 90),
    (2, 3, 80),
    (2, 4, 85)
;
Run Code Online (Sandbox Code Playgroud)

我也有以下查询:

(select sid from took) except all (select sid from took where grade < 90);
Run Code Online (Sandbox Code Playgroud)

1,1,2由于在这种情况下等级值> = 90 ,因此产生了预期的输出。但是,当我删除该all子句以

select sid from took) except (select sid from took where grade < 90);
Run Code Online (Sandbox Code Playgroud)

输出为1。我知道all确定是否存在重复项,因此在这种情况下,我希望输出1,2不是1。发生什么了?

sql postgresql

0
推荐指数
1
解决办法
1131
查看次数

yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'格式

我正在尝试将GMT转换为IST.

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS");
  Date c= sdf.parse("2017-03-31T10:38:14.4723017Z");

  Date date = new Date();
  DateFormat istFormat = new SimpleDateFormat();
  DateFormat gmtFormat = new SimpleDateFormat();
  TimeZone gmtTime = TimeZone.getTimeZone("GMT");
  TimeZone istTime = TimeZone.getTimeZone("IST");

  istFormat.setTimeZone(gmtTime);
  gmtFormat.setTimeZone(istTime);
  System.out.println("GMT Time: " + istFormat.format(c));
  System.out.println("IST Time: " + gmtFormat.format(c));
Run Code Online (Sandbox Code Playgroud)

我的输出是

GMT Time: 31/3/17 6:26 AM
IST Time: 31/3/17 11:56 AM
Run Code Online (Sandbox Code Playgroud)

但我的实际输出应该是

GMT Time: 31/3/17 5:08 AM
IST Time: 31/3/17 10:38 AM
Run Code Online (Sandbox Code Playgroud)

我的代码出了什么问题?

java datetime-conversion

0
推荐指数
1
解决办法
4248
查看次数

将CSV导入Postgres:同时更新和插入

所以我对Postgresql很新,并开始使用Postgres9.6上的pgadmin4测试一些东西.

问题:

我有一个表:test(id,text)

在这个表中,我有10行数据.现在我想导入一个包含12行的CSV来更新测试表.前10行中的某些文本已更改,我想从CSV中插入另外2行.

我知道你可以从表中截断所有数据,然后再从CSV导入所有数据,但这不是一个很好的方法.我想更新现有数据并使用一个查询插入新数据.

我已经找到了一个应该通过使用临时表来解决这个问题的函数.这会更新现有行的正确性,但不会插入另外2行

CREATE OR REPLACE FUNCTION upsert_test(integer,varchar) RETURNS VOID AS $$
DECLARE
BEGIN
    UPDATE test
SET id = tmp_table.id,
text = tmp_table.text
FROM tmp_table
WHERE test.id = tmp_table.id;
IF NOT FOUND THEN
INSERT INTO test(id,text) values 
(tmp_table.id,tmp_table.text);
END IF;
END;
$$ Language 'plpgsql';

DO $$ BEGIN
PERFORM upsert_test(id,text) FROM test;
END $$;
Run Code Online (Sandbox Code Playgroud)

那么我还需要更改以使插件工作?

csv postgresql postgresql-9.6

0
推荐指数
1
解决办法
656
查看次数

postgresql 中的条件插入语句

我正在尝试运行条件插入语句,但遇到问题。声明如下:

insert into category_content (category_id, content_id, content_type_id, priority) (select 29, id, 1, 1 from article where blog_id = 80) 
where not exists(
select * from category_content where category_id = 29 and firstname in (select id from article where blog_id = 80)
);
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

insert into category_content (category_id, content_id, content_type_id, priority) (select 29, id, 1, 1 from article where blog_id = 80) 
where not exists(
select * from category_content where category_id = 29 and firstname in (select id from article where …
Run Code Online (Sandbox Code Playgroud)

sql postgresql

0
推荐指数
1
解决办法
3213
查看次数

连续集团

我有下表:

SELECT * 
FROM mytable 
ORDER BY id;

id  name    code   time
1    A      111     1
2    A      111     2
3    A      888     3
4    A      888     4
5    A      888     5
6    A      888     6
7    A      888     7
8    A      111     8
9    A      111     9
10    A     111     10
Run Code Online (Sandbox Code Playgroud)

我需要得到这样的结果:

name    code    times_between
A       111     1,2
A       888     3,7
A       111     8,10
Run Code Online (Sandbox Code Playgroud)

是否可以按"块"分组?我需要根据时间进行区分,所以我不能只按名称,代码分组,只获取第一个和最后一个元素.

sql postgresql gaps-and-islands

0
推荐指数
1
解决办法
215
查看次数