sql

PDO and binding multiple value sets during insert - recently

丶灬走出姿态 提交于 2021-02-17 06:07:27
问题 Using PDO in PHP, when having to insert multiple rows into a table at once, I've used sql that looks something like this: INSERT INTO some_names (firstName, lastName) VALUES ('Joe', 'Smith'),('Fred','Sampson'),('Lisa','Pearce'); As you can see I'm inserting three rows with one statement. The reason I do this is that I believe it is more efficient than executing three distinct statements to insert the rows. So my question is this: how do I do this in PHP if I want to be able to bind my values

PDO and binding multiple value sets during insert - recently

我是研究僧i 提交于 2021-02-17 06:05:44
问题 Using PDO in PHP, when having to insert multiple rows into a table at once, I've used sql that looks something like this: INSERT INTO some_names (firstName, lastName) VALUES ('Joe', 'Smith'),('Fred','Sampson'),('Lisa','Pearce'); As you can see I'm inserting three rows with one statement. The reason I do this is that I believe it is more efficient than executing three distinct statements to insert the rows. So my question is this: how do I do this in PHP if I want to be able to bind my values

“Subquery returned more than 1 value” error

£可爱£侵袭症+ 提交于 2021-02-17 06:05:03
问题 SELECT [schoolname] AS combinationschools, CASE WHEN [schoolname] LIKE '%/%' THEN (SELECT value FROM [dbo].[Split]('/', '#6/#9E/#9M')) END AS schoolname FROM [dbo].[schools]; i'm getting q sql error like wise- Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 回答1: When you use a subquery like this, you can only have one record in the result set for each record. Clearly your table Split has

“Subquery returned more than 1 value” error

喜欢而已 提交于 2021-02-17 06:04:31
问题 SELECT [schoolname] AS combinationschools, CASE WHEN [schoolname] LIKE '%/%' THEN (SELECT value FROM [dbo].[Split]('/', '#6/#9E/#9M')) END AS schoolname FROM [dbo].[schools]; i'm getting q sql error like wise- Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. 回答1: When you use a subquery like this, you can only have one record in the result set for each record. Clearly your table Split has

Dividing 2 numbers returns 0

不羁岁月 提交于 2021-02-17 05:57:28
问题 I'm trying to divide 2 counts in order to return a percentage. The following query is returning 0 : select ( (select COUNT(*) from saxref..AuthCycle where endOfUse is null and addDate >= '1/1/2014') / (select COUNT(*) from saxref..AuthCycle where addDate >= '1/1/2014') ) as Percentage Should I be applying a cast? 回答1: I would do it differently, using two sum s: select sum ( case when endOfUse is null and addDate >= '1/1/2014' then 1 else 0 end ) * 100.0 -- if you want the usual 0..100 range

Get Distinct Entries Based On Specific Column in Entity Framework

感情迁移 提交于 2021-02-17 05:57:21
问题 I have a SQLite table that contains every test result we've run, and I'm looking to write an entity framework query that returns only the most recent test result per project. Normally, I'd assume this would be "group by project id, return row with the max updated value," or, alternatively, "sort by date and return first". However, when I try the query, I keep getting Entity Framework "could not be translated" errors. Here's what I've tried: results = await _context.Results .Include(x => x

Get Distinct Entries Based On Specific Column in Entity Framework

只愿长相守 提交于 2021-02-17 05:57:08
问题 I have a SQLite table that contains every test result we've run, and I'm looking to write an entity framework query that returns only the most recent test result per project. Normally, I'd assume this would be "group by project id, return row with the max updated value," or, alternatively, "sort by date and return first". However, when I try the query, I keep getting Entity Framework "could not be translated" errors. Here's what I've tried: results = await _context.Results .Include(x => x

SQL ERROR in Syntax when using WITH [duplicate]

大城市里の小女人 提交于 2021-02-17 05:56:20
问题 This question already has answers here : How do you use the “WITH” clause in MySQL? (7 answers) Closed 4 years ago . I want to use a SQL Query with the WITH clause an I get a Syntax Error. I´m using MySQL Version 5.6.28 Here a simple Code example WITH alias_test AS (SELECT id, title FROM `tips_locations`) SELECT id, title FROM alias_test Here the error I get in my SQL Tool You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax

Select columns of table index

强颜欢笑 提交于 2021-02-17 05:41:05
问题 Oracle has a query that selects the existing indexes of a table. For example: SELECT * FROM user_indexes WHERE table_name = 'CM_WCEL'; But I need to recreate the index creation statement. How can I get the remaining information like the affected columns, etc? 回答1: To get the complete DDL for each index, use dbms_metadata.get_ddl() : select index_name, dbms_metadata.get_ddl('INDEX', index_name) as ddl from user_indexes where table_name = CM_WCEL'; The DDL is returned as a CLOB. Depending on

ORA-00904: “Good”: invalid identifier ORA-06512

雨燕双飞 提交于 2021-02-17 05:37:28
问题 1.getting invalid identifier error while updating row_val variable char value 'Good' into the table 2.while inserting number it's working fine but strings its getting errors 3. declare count_temp number; csv_data varchar2(1000); val varchar2(100); row_val varchar2(100); sqlcmd varchar2(3000); col_name varchar2(100); col_data varchar2(100); begin csv_data:='good,son,r,,happy'; col_data:='varchar2(100)'; select regexp_count(csv_data, ',') + 1 into count_temp from dual; dbms_output.put_line