sql

Sum column up to the current row in SQL?

不想你离开。 提交于 2021-02-17 03:40:08
问题 I'm trying to sum a column up to the current row (in SQL Server). How do I do this? select t1.CounterTime, t1.StartTime, t1.EndTime, isNull(t1.value, 0) as value1, -- How do I make Total1 the sum of t1.value over all previous rows? sum( isNull(t1.value, 0) ) over (partition by t1.CounterTime order by t1.CounterTime) as Total1 from SomeTable t1 order by t1.CounterTime But I got the partition by wrong... ╔═══╦═════════════════════════╦═════════════════════════╦═════════════════════════╦════════

How do I generate all the dates of Sunday between 2 dates in oracle sql?

无人久伴 提交于 2021-02-17 03:37:17
问题 How do I generate all the dates of Sunday between 2 dates in oracle SQL? Example if I want all the Sundays between "01/10/2018" and "31/12/2018" the output will be: 07/10/2018 14/10/2018 21/10/2018 ... 30/12/2018 Also how do I generate all the dates between 2 dates? Example: from "01/12/2018" to "31/12/2018" Output will be: 01/12/2018 02/12/2018 03/12/2018 ... 31/12/2018 回答1: Here's how; the CTE ( dates ) creates a "calendar" of all dates starting from 2018-10-01 , for number of days between

Creating table via SQL Command Line, invalid identifier

橙三吉。 提交于 2021-02-17 03:31:18
问题 I'm currently learning SQL and I've installed oracle 11g express on my system. I'm trying to create a table however when I try to run the below command I get the following Error Message: ERROR at line 3: ORA-00904 : invalid identifier CREATE TABLE PROJECTS ( proID NUMBER(4) NOT NULL, Desc CHAR(20), sDate DATE, eDate DATE, Budget NUMBER(7,2), maxStaff NUMBER(2) ); Can anybody please tell me what I'm doing wrong? Thanks for all the replies, I ran this command succesfully: CREATE TABLE PROJECTS

Codeigniter Delete … Where … and

血红的双手。 提交于 2021-02-17 03:22:21
问题 I need a little help. How can i send this query with codeigniter? Delete FROM friendconnect WHERE who = 5 and whos = 1 OR whos = 5 and who = 1; I found only that: $this->db->where('id', $id); $this->db->delete('mytable'); Thanks everybody! 回答1: $this->db->where('who', 5); $this->db->where('whos', 1); $this->db->or_where('whos', 5); $this->db->where('who', 1); $this->db->delete('friendconnect'); This is also an alternative: $this->db->where('who', 5)->where('whos', 1)->or_where('whos', 5)-

Codeigniter Delete … Where … and

南笙酒味 提交于 2021-02-17 03:22:19
问题 I need a little help. How can i send this query with codeigniter? Delete FROM friendconnect WHERE who = 5 and whos = 1 OR whos = 5 and who = 1; I found only that: $this->db->where('id', $id); $this->db->delete('mytable'); Thanks everybody! 回答1: $this->db->where('who', 5); $this->db->where('whos', 1); $this->db->or_where('whos', 5); $this->db->where('who', 1); $this->db->delete('friendconnect'); This is also an alternative: $this->db->where('who', 5)->where('whos', 1)->or_where('whos', 5)-

Is there in SQL a way to enforce unicity of undirected edge?

不问归期 提交于 2021-02-17 03:21:35
问题 create table Location ( id integer primary key(1, 1), latitude decimal(8,6), longitude decimal(9,6), address varchar(100), name varchar(60) unique ); create table Journey ( id integer primary key(1,1), id_from integer foreign key references Location(id), id_to integer foreign key references Location(id), name varchar(100) unique, unique(id_from, id_to) ); With this schema, you could create 2 different journeys for a pair of locations, one for the way in and one for the way back. What I want

Is it possible to create a column in MySQL with an expression as a default value?

点点圈 提交于 2021-02-17 03:20:23
问题 How would one implement this in MySQL: CREATE TABLE employee ( employeemonthly DECIMAL(10,2), employeeyearly DECIMAL(10,2) DEFAULT employeemonthly*12 ); 回答1: use a insert trigger for that. Something like this DELIMITER | CREATE TRIGGER default_yearly BEFORE INSERT ON employee FOR EACH ROW BEGIN SET NEW.employeeyearly = NEW.employeemonthly * 12; END; | DELIMITER ; 回答2: I would use a view: CREATE VIEW vemployees AS SELECT e.employeemonthly, e.employeemonthly * 12 AS employeeyearly FROM EMPLOYEE

How do I write a function in plpgsql that compares a date with a timestamp without time zone?

社会主义新天地 提交于 2021-02-17 03:12:31
问题 I want to write a function that returns a table with all the rows between firstDate and lastDate . The rows have datatype timestamp without time zone They also have to be of a specific node id. This is my function: CREATE OR REPLACE FUNCTION get_measurements_by_node_and_date(nodeID INTEGER, firstDate date, lastDate date) RETURNS TABLE (measurement_id INTEGER, node_id INTEGER, carbon_dioxide DOUBLE PRECISION, hydrocarbons DOUBLE PRECISION, temperature DOUBLE PRECISION, humidity DOUBLE

How do I write a function in plpgsql that compares a date with a timestamp without time zone?

こ雲淡風輕ζ 提交于 2021-02-17 03:08:24
问题 I want to write a function that returns a table with all the rows between firstDate and lastDate . The rows have datatype timestamp without time zone They also have to be of a specific node id. This is my function: CREATE OR REPLACE FUNCTION get_measurements_by_node_and_date(nodeID INTEGER, firstDate date, lastDate date) RETURNS TABLE (measurement_id INTEGER, node_id INTEGER, carbon_dioxide DOUBLE PRECISION, hydrocarbons DOUBLE PRECISION, temperature DOUBLE PRECISION, humidity DOUBLE

Changes to database session context persists with pooled connection reuse

流过昼夜 提交于 2021-02-17 02:47:45
问题 In my application, I have a connection pool that I use to obtain connections to Oracle database. I need to execute statements that call stored procedures that might affect the database session context/variables so that these changes affect only the current use of the connection. When I close the connection and obtain another connection from the pool, I want it like a new connection/session at which the effect of the procedure doesn't exist. Unfortunately, this doesn't happen. So I obtain a