select-query

Mysql select query to find a value in certain range

时光怂恿深爱的人放手 提交于 2020-01-30 11:40:27
问题 I have a items table, id item min_price max_price ----------------------------------- 1 item1 100 500 2 item2 150 400 3 item3 410 700 4 item4 330 700 5 item3 420 600 When I pass the price value 450 , I expect a result with 450 containing range values, ie, id item min_price max_price ----------------------------------- 3 item3 410 700 5 item3 420 600 How do I get this result ? I tried this query, SELECT * FROM items where min_price >= 450 AND max_price <= 450 But no result. How to get the

SQL query to get min, max rows

人走茶凉 提交于 2019-12-24 19:44:24
问题 I have following sample data, I want to get min and max time of every consecutive status. cat subcat status logtime fruits apple 0 30-10-2017 06:00 fruits apple 0 30-10-2017 06:03 fruits apple 0 30-10-2017 06:06 fruits apple 0 30-10-2017 06:09 fruits apple 0 30-10-2017 06:12 fruits apple 0 30-10-2017 06:15 fruits apple 0 30-10-2017 06:18 fruits apple 0 30-10-2017 06:21 fruits apple 0 30-10-2017 06:24 fruits apple 0 30-10-2017 06:27 fruits apple 0 30-10-2017 06:30 fruits apple 0 30-10-2017 06

How to use passed parameter as table Name in Select query python?

给你一囗甜甜゛ 提交于 2019-12-24 15:51:40
问题 i have the following function which extracts data from table, but i want to pass the table name in function as parameter... def extract_data(table): try: tableName = table conn_string = "host='localhost' dbname='Aspentiment' user='postgres' password='pwd'" conn=psycopg2.connect(conn_string) cursor = conn.cursor() cursor.execute("SELECT aspects_name, sentiments FROM ('%s') " %(tableName)) rows = cursor.fetchall() return rows finally: if conn: conn.close() when i call function as extract_data

Un-group a row into many rows based on date parts

会有一股神秘感。 提交于 2019-12-24 10:49:33
问题 I'm using MySql and I have a Policy table with StartDate and EndDate columns. How can I write a SELECT query to give me a new row for each month in the date range between these 2 columns. For example if I have a policy with: Id StartDate EndDate 123456 2011-05-25 2011-07-26 I would want to see: Id PolicyId StartDate EndDate 1 123456 2011-05-25 2011-06-24 2 123456 2011-06-25 2011-07-24 3 123456 2011-07-25 2011-07-26 回答1: I'm not sure about performance because I'm not much experienced with

Executing stored procedure in select query

隐身守侯 提交于 2019-12-11 18:09:27
问题 I'm using SQL Server 2008 R2 and I am trying to run a query where a stored procedure will also be executed. The query is: select a.custnmbr, a.custname, a.salsterr, b.itemnmbr, b.itemdesc, d.slprsnid ,exec dbo.QtySoldPerMonth a.custnmbr, b.itemnmbr, @year from rm00101_temp a, iv00101_temp b inner join sop30300_RPT c on b.itemnmbr = c.itemnmbr inner join sop30200_RPT d on c.sopnumbe = d.sopnumbe where b.itemnmbr like @houseCode + '%' and itmclscd like @classCode + '%' AND DATEPART(year, d

MYSQL select query using count (*)

人盡茶涼 提交于 2019-12-10 18:24:19
问题 i have a problem concerning a select query in MYSQL i have two different tables and i want to obtain a certain result i used COUNT method which gave me only the results (>=1) But in reality , i want to use all counts with zero included how to do it? My query is: SELECT first.subscriber_id, second.tag_id, COUNT(*) FROM content_hits first JOIN content_tag second ON first.content_id=second.content_id GROUP BY second.Tag_id,first.Subscriber_id<br> First table:Content_hits CONTENT_ID SUBSCRIBER_ID

Perform a simple select query in Firebase Firestore

天涯浪子 提交于 2019-12-08 11:56:22
问题 How can I perform a simple search in Firebase Firestore to check if a record exists in a collection? I've seen this code in the documentation, but it is not complete. // Create a reference to the cities collection var citiesRef = db.collection('cities'); // Create a query against the collection var queryRef = citiesRef.where('state', '==', 'CA'); In my use case I want to check the rejected contacts collection for a given number. This is my code const collectionRef = db.collection(

persian/arabic search in sqlite android gives bad result

 ̄綄美尐妖づ 提交于 2019-12-03 16:16:49
问题 i have a problem with sqlite database. it seems to not support full persian/arabic characters. when i search some fields based on persian chars, most of the times Sqlite can't recognize those chars. i insert data into database by copy them from HTML file. so when i type string and search, no result show. but if i copy string and search, it works. The string from the HTML file is: "احكام خمس" The typed string is: "احکام خمس" 回答1: These strings are different. The HTML string begins with the

persian/arabic search in sqlite android gives bad result

眉间皱痕 提交于 2019-12-03 05:25:12
i have a problem with sqlite database. it seems to not support full persian/arabic characters. when i search some fields based on persian chars, most of the times Sqlite can't recognize those chars. i insert data into database by copy them from HTML file. so when i type string and search, no result show. but if i copy string and search, it works. The string from the HTML file is: "احكام خمس" The typed string is: "احکام خمس" These strings are different. The HTML string begins with the characters U+0627, U+062D, and U+0643 (Alef, Hah, and Kaf). The third character of the typed string is not U

SQL Server PRINT SELECT (Print a select query result)?

我只是一个虾纸丫 提交于 2019-11-30 12:23:29
问题 I am trying to print a selected value, is this possible? Example: PRINT SELECT SUM(Amount) FROM Expense 回答1: You know, there might be an easier way but the first thing that pops to mind is: Declare @SumVal int; Select @SumVal=Sum(Amount) From Expense; Print @SumVal; You can, of course, print any number of fields from the table in this way. Of course, if you want to print all of the results from a query that returns multiple rows, you'd just direct your output appropriately (e.g. to Text). 回答2