sql

Python postgreSQL sqlalchemy query a DATERANGE column

百般思念 提交于 2021-02-19 09:42:49
问题 I have a booking system and I save the booked daterange in a DATERANGE column: booked_date = Column(DATERANGE(), nullable=False) I already know that I can access the actual dates with booked_date.lower or booked_date.upper For example I do this here: for bdate in room.RoomObject_addresses_UserBooksRoom: unaviable_ranges['ranges'].append([str(bdate.booked_date.lower),\ str(bdate.booked_date.upper)]) Now I need to filter my bookings by a given daterange. For example I want to see all bookings

Conversion failed when converting the nvarchar value to data type int - Error Message

纵饮孤独 提交于 2021-02-19 09:13:22
问题 My Query Select * from MyTable The table consists 300k rows. It runs for 200k+ rows and this error pops up. How to handle this to get the full data? Does MyTable have any computed columns? Table consists of a computed column with the name IsExceeds which is given below for your reference. This is the computed column formula: (CONVERT([int],[Pro_PCT])-CONVERT([int],replace([Max_Off],'%',''))) Field Definitions: [Pro_PCT] [nvarchar](50) NULL, [Max_Off] [nvarchar](50) NULL, [IsExceeds] AS

MySQL dense rank for each group/partition

岁酱吖の 提交于 2021-02-19 08:57:39
问题 I am trying to build a dense rank kind of functionality but not exactly dense rank. I want to rank each group but within each group I want to keep the rank same for same values. I've written the following query which gives me a dense rank kind of functionality SELECT id, item_code @curRank := @curRank + 1 AS rank FROM table t, (SELECT @curRank := 0) r WHERE <several filters> Whereas, I want this The closest question I found is this one MySQL give a rank to each group Please help. 回答1: You can

INSERT or UPDATE bulk data from dataframe/CSV to PostgreSQL database

帅比萌擦擦* 提交于 2021-02-19 08:57:05
问题 Requirement: Insert new data and update existing data in bulk (row count > 1000) from a dataframe/CSV (which ever suites) and save it in PostgreSQL database. Table: TEST_TABLE CREATE TABLE TEST_TABLE ( itemid varchar(100) NOT NULL PRIMARY KEY, title varchar(255), street varchar(10), pincode VARCHAR(100)); INSERT: ['756252', 'tom title', 'APC Road', '598733' ], ['75623', 'dick title', 'Bush Road', '598787' ], ['756211', 'harry title', 'Obama Street', '598733' ] dataframe content: data = [[

Showing Trigger DBMS_OUTPUT.PUT_LINE in Oracle Apex

不打扰是莪最后的温柔 提交于 2021-02-19 08:57:05
问题 I have a trigger: CREATE OR REPLACE TRIGGER Med_Allergy_Warning BEFORE INSERT ON Prescription FOR EACH ROW BEGIN IF (Find_ADR(:NEW.Visit_ID, :NEW.Medication_ID) != 'GOOOO') THEN DBMS_OUTPUT.PUT_LINE('Medication ('||:NEW.Medication_ID||') May cause an allergic reaction… You are warned!'); ELSE DBMS_OUTPUT.PUT_LINE('Medication ('||:NEW.Medication_ID||') was prescribed successfully!'); END IF; END;/ That outputs a DBMS_OUTPUT.PUT_LINE whenever a user enters a prescription that may cause allergic

MYSQL: SELECT sum of field values while also SELECTing unique values?

百般思念 提交于 2021-02-19 08:43:19
问题 I'd like to count the number of purchases of each item while also, depending on who's viewing the content, show whether the user has purchased the content. Because the number of items and purchases could become large I'm reluctant to throw in more JOINs to accomplish this because that would seem not performant. Basically, I'd like to have a did_i_buy field somewhere in the following query without adding another JOIN . Is this possible? Let's say for user_name=tom : SELECT Items.item_id, item

Transact-SQL Select statement results with bad GUID

冷暖自知 提交于 2021-02-19 08:23:21
问题 We have a table with GUID primary keys. When I search for a specific key, I can use either: SELECT * FROM products WHERE productID='34594289-16B9-4EEF-9A1E-B35066531DE6' SELECT * FROM products WHERE productID LIKE '34594289-16B9-4EEF-9A1E-B35066531DE6' RESULT (for both): product_ID Prd_Model ------------------------------------ -------------------------------------------------- 34594289-16B9-4EEF-9A1E-B35066531DE6 LW-100 (1 row affected) We have a customer who uses our ID but adds more text

SQL turning rows into columns and populating with values

一世执手 提交于 2021-02-19 08:22:08
问题 I'm not quite sure why this table was designed this way, but it's making it hard to solve my problem. Looking at the data: NAME TYPE_NAME DEFAULT_VALUE VALUE TEST 1 Currency Null 14 TEST 1 Event Count 0 0 TEST 1 Usage 8 Null TEST 1 Events Amt 0 0 TEST 1 Usage Amt Null 13 TEST 1 From Date Null 5 TEST 1 To Date 6 Null TEST 1 Traffic Scenario Null 2 TEST 1 Band 1 Null TEST 1 Service 15 Null TEST 1 Tariff Rate Name Null 4 TEST 2 Currency EUR 0 TEST 2 Event Count Null 9 TEST 2 Usage 10 Null TEST 2

Find min and max for subsets of consecutive rows - gaps and islands

半城伤御伤魂 提交于 2021-02-19 08:13:26
问题 Trying to build a query. The input is ordered by rownumber in column 'rn' starting with 1 for each unique value in 'name' and defining a given sequence of entries in 'act'. In column 'act' it holds two values in multiple occurence, >sleep< and >wake<. The goal is to find for each consecutive set of rows of one of those values the minimum and maximum value of startt and endd. This shall be the input: name act rn startt endd ---------- ---------- ------ ------ ------ jimmy sleep 1 1 3 jimmy

ms access, need to get all rows with a distinct column

一曲冷凌霜 提交于 2021-02-19 08:13:05
问题 I have a table called "parts" which stores information on electrical connectors including contacts, backshells etc. all parts that are part of an assembly have a value in a column called "assemblyID". There is also a column called "partDefID", in this column connectors will have a value of 2, contacts will be 3. I need to get rows for all connectors that have a unique assemblyID. It's easy to get rows that represent connectors just by selecting rows with a partDefID of 2 but this will return