where

MYSQL hide field data if value in another field is set

霸气de小男生 提交于 2020-01-03 05:10:25
问题 Got a table like: art. type price a b 1 a c 2 would it be possible with a select to show filtered content as: art. type price a b a c 2 so that if the type is "b" don't show price data? select art, type, price from x where type="b" hide price 回答1: Logic of this sort probably best belongs in the presentation, rather than database, layer of your application. However, it is nevertheless possible using either MySQL's IF() function or its CASE expression—for example: SELECT art, type, IF(type='b'

MYSQL MIN in WHERE clause

喜你入骨 提交于 2020-01-02 13:52:38
问题 OK, so I'm working on a home theater system, and to display the list of TV series I have been selecting the first episode of the first season and displaying the associated information for just that episode, then you can drill down to others. That way I can keep all the movies and all the TV shows in a single table which makes the playback functions much easier. The problem is, some of the series I don't have the first episode in the database, and I want them to appear anyway, so I want to

MYSQL MIN in WHERE clause

故事扮演 提交于 2020-01-02 13:51:53
问题 OK, so I'm working on a home theater system, and to display the list of TV series I have been selecting the first episode of the first season and displaying the associated information for just that episode, then you can drill down to others. That way I can keep all the movies and all the TV shows in a single table which makes the playback functions much easier. The problem is, some of the series I don't have the first episode in the database, and I want them to appear anyway, so I want to

WHERE clause - record with a NULL column is not displayed

為{幸葍}努か 提交于 2020-01-02 10:19:53
问题 Conception In the Org_Structure there are unique combinations of departments and offices. In the Emp_Positions table each employee is assigned to the certain combination of department/office or "Chain" in the organizational structure. But some employees should not belong to offices, so they are assigned to a chain where office_id column is NULL. On the second image such employee is colored in red. The Bug The provided stored procedure can find only employees of those chains where both dep_id

SQL: Conditional AND in where

≯℡__Kan透↙ 提交于 2020-01-02 05:09:26
问题 I'm trying to create a stored procedure that allows parameters to be omitted, but ANDed if they are provided: CREATE PROCEDURE MyProcedure @LastName Varchar(30) = NULL, @FirstName Varchar(30) = NULL, @SSN INT = NULL AS SELECT LastName, FirstName, RIGHT(SSN,4) as SSN FROM Employees WHERE ( (LastName like '%' + ISNULL(@LastName, '') + '%') AND (FirstName like '%' + ISNULL(@FirstName, '') + '%') ) AND (SSN = @SSN) I only want to do the AND if there's an @SSN provided. Or is there some other way

Convert string to int inside WHERE clause of SQLITE statment

£可爱£侵袭症+ 提交于 2020-01-02 04:02:26
问题 I want to achieve this: SELECT * FROM linkledger WHERE toInt(reputation) > 100; but the function toInt doesnt exist? Is there one? I found this now but not working, which implies i have a more fundemental problem. BECAUSE THIS IS CORRECT SELECT * FROM linkledger WHERE cast(reputation AS INTEGER) > 100; 回答1: Use CAST(reputation AS INTEGER). 回答2: I will leave Anik Islam Abhi's answer as the correct one because it will apply in most cases but I just want it on record that I only managed to fix

Rails 4 where,order,group,count include zero's - postgresql

我们两清 提交于 2020-01-01 19:25:29
问题 Here is my query: User.where("created_at >= ? AND created_at <=?", date1,date2).order('DATE(created_at) DESC').group("DATE(created_at)").count and I get output as: {Thu, 15 May 2014=>1} But I want to get output as 0 for the rest of the days. For ex {Thu, 15 May 2014=>1,Fri, 15 May 2014=>0} What I want to get is Users created in a date range , ordered and grouped by created_at and number of such Users for each day. When no users are there for a particular day it should return 0, which the

Rails 4 where,order,group,count include zero's - postgresql

一个人想着一个人 提交于 2020-01-01 19:25:29
问题 Here is my query: User.where("created_at >= ? AND created_at <=?", date1,date2).order('DATE(created_at) DESC').group("DATE(created_at)").count and I get output as: {Thu, 15 May 2014=>1} But I want to get output as 0 for the rest of the days. For ex {Thu, 15 May 2014=>1,Fri, 15 May 2014=>0} What I want to get is Users created in a date range , ordered and grouped by created_at and number of such Users for each day. When no users are there for a particular day it should return 0, which the

JPA - Batch/Bulk Update - What is the better approach?

为君一笑 提交于 2020-01-01 03:19:13
问题 I found that JPA does not support the following Update: Update Person p set p.name = :name_1 where p.id = :id_1, p.name = :name_2 where p.id = :id_2, p.name = :name_3 where p.id = :id_3 .... // It could go on, depending on the size of the input. Could be in 100s So I have two options: Option 1: Query q = em.createQuery("Update Person p set p.name = :name where p.id = :id"); For ( int x=0; PersonsList.length; x++ ) { // add name and id parameters em.executeUpdate(); } Questions: Is this all

Which performs first WHERE clause or JOIN clause

假装没事ソ 提交于 2020-01-01 01:48:06
问题 Which clause performs first in a SELECT statement? I have a doubt in select query on this basis. consider the below example SELECT * FROM #temp A INNER JOIN #temp B ON A.id = B.id INNER JOIN #temp C ON B.id = C.id WHERE A.Name = 'Acb' AND B.Name = C.Name Whether, First it checks WHERE clause and then performs INNER JOIN First JOIN and then checks condition? If it first performs JOIN and then WHERE condition; how can it perform more where conditions for different JOIN s? 回答1: The conceptual