where-clause

Set where clause on field

眉间皱痕 提交于 2019-12-13 01:27:43
问题 I have a base entity that holds a enum field called State. public enum State { DELETED(0), ACTIVE(1) ; private int value; private State(int value) { this.value = value; } public int getValue() { return this.value; } } Is there a JPA annotated way to set the where clauses of the generated queries to retrieve only entities that the state field is "ACTIVE"? The reason is that if i have an entity "A" that holds a list of entities "B", when i retrieve from the DB an instance of "A" and initialize

Return results of query based on todays date in SQL (MySQL) Part 2

久未见 提交于 2019-12-13 00:46:47
问题 I posted another question which was resolved perfectly however I now need to apply the same code I was given to a different piece of MySQL code. What I have is SELECT value, COUNT(*) AS 'num' FROM table_c WHERE table_c_id IN (9, 17, 25) GROUP BY value What I would like to do now is only show the results if they have been entered on the current date? The current code snippet I have for checking the current date, which works great is (the date is in unixtime format) ( xxxxxxxxxxxxxx and curdate

Pandas: Select rows based on multiple object values inside a column

风格不统一 提交于 2019-12-12 15:02:44
问题 I have a pandas dataframe in which one of the column contains user information. Each record of this column is a list which in turn contains dictionaries of user information. Like the follwoing: USER id 1 [{u'STATUS': u'INACTV', u'NAME': 'abc'},{u'STATUS': u'ACTV', u'NAME': 'xyz'}] 634618 2 [{u'STATUS': u'INACTV', u'NAME': 'abc'},{u'STATUS': u'ACTV', u'NAME': 'xyz'}] 642054 3 [{u'STATUS': u'ACTV', u'NAME': 'abc'},{u'STATUS': u'ACTV', u'NAME': 'xyz'}] 631426 I want to select only the rows where

Query running longer by adding unused WHERE conditions

送分小仙女□ 提交于 2019-12-12 07:16:57
问题 I've hit an interesting snag (interesting to me at least). Below is a general idea of what my query looks like. Assume @AuthorType is an input to the stored procedure and that there are various specialized conditions each place I've put comments. SELECT * FROM TBooks WHERE (--...SOME CONDITIONS) OR (@AuthorType = 1 AND --...DIFFERENT CONDITIONS) OR (@AuthorType = 2 AND --...STILL MORE CONDITIONS) What's interesting to me is that if I execute this SP with @AuthorType = 0, it runs slower than

mysql query, nested where clauses

北战南征 提交于 2019-12-12 05:19:54
问题 I have a working query that counts all distinct values from table LDS where STATUS = 'OK' AND DATE >= '2012' AND if there are multiple identical IDs then count the one with the newest date if this id has a status of "ok": COUNT(DISTINCT lds1.ID) FROM LDS lds1 LEFT JOIN LDS lds2 ON lds1.ID = lds2.ID AND lds1.Date < lds2.Date AND lds1.Status = 'ok' WHERE lds1.Date >= '2012' AND lds1.Status = 'ok' AND lds2.ID IS NUL I now need to add another condition to be TRUE before the above query is run:

Does row exist and multiple where

微笑、不失礼 提交于 2019-12-12 04:35:48
问题 I just asked this question Multiple Where conditions, but realised there was more to it (and didn't want to confuse the other question). I have a table that looks like this: meta_id - id - meta_key - meta_value 1 1 school Some School 1 2 2 school Some School 2 3 2 hidden 1 4 3 school Some School 3 5 4 school Some School 4 6 5 school Some School 5 7 5 hidden 1 Thanks to my previous question I have this syntax: SELECT DISTINCT m1.id FROM metadata m1 join metadata m2 on m1.id = m2.id WHERE (m1

Why does the “where id in (n1, n2, n3, …, n2000)” incredibly slow? [duplicate]

隐身守侯 提交于 2019-12-12 04:21:39
问题 This question already has an answer here : Can MySQL FIND_IN_SET or equivalent be made to use indices? (1 answer) Closed 3 years ago . I have a table which has about one hundred million rows, and the column 'id' is the primary key, and it is the only key in the table. I do a query like: SELECT id,name FROM table WHERE id IN (id1, id2, id3, id4, ..., id1000); These 1000 ids inside "IN" are actually const integers which are pre-caculated by a program. But Mysql spends about one minute to do the

Confusion between HAVING and WHERE, SQL Server

放肆的年华 提交于 2019-12-12 03:53:05
问题 I am trying to fetch all vendors whose product's quantity ( SUM ) is equal to zero. This is what I have done so far but it doesn't return any row nor it gives any error. I am making sure there are products whose quantity is zero and script is running on proper database. select VI.Name, Cp.ProductName from VendorInfo VI inner join VendorTrading VT on VI.Id = VT.VendorId inner join CustomerProducts CP on VT.Id = CP.VendorTradingId group by VI.Name, CP.ProductName having sum(CP.ProductQuantity)

SQL select statement in where clause

假装没事ソ 提交于 2019-12-12 02:57:08
问题 Hi there I am trying to execute a query but cannot seem to get it right. SELECT * FROM table WHERE id IN (SELECT * FROM table WHERE description = 'A') AND description = 'B' Above is the query that I have got, the select * from table where description = A works as expected when ran alone I just need to make the where clause to work so I can see any id that has a description of A and B. 回答1: You will be getting multiple columns from the sub query when I assume you only want the id column:

multiple columns in where clause query mysql

时光毁灭记忆、已成空白 提交于 2019-12-12 02:56:27
问题 selectbox with multiple columns from mysql database The following code was the winning code from zgr024 <?php include '../config.php'; $sql = "SELECT * FROM megabase"; $resultaat = mysql_query($sql) or die (mysql_error()); $domains = array(); while ($row = mysql_fetch_array($resultaat)) { if (!empty($row['domeinnaam1'])) $domains[] = $row['domeinnaam1']; if (!empty($row['domeinnaam2'])) $domains[] = $row['domeinnaam2']; } ?> <select size="1" name="domeinnaam"> <?php foreach ($domains as