Solved

Need help with MySQL Query

Posted on 2013-11-02
3
317 Views
Last Modified: 2013-11-03
Hello, I need help with a query issue I'm having.... I've added another column within the cw_ship_method table called "ship_method_exempt". The new column has some list values of...

1. po, rs
2. po
3. po
4. (empty)
5. (empty)
6. po, co

I know i could normalize the table. I did try doing that but that didn't seem to be pulling the right records as well. I would like to try solving it with the list values instead. Just because I would like to learn how to for one reason and the table won't be expanding at all. I know in normal practices normalizing is recommended though. The part I'm not focusing on is here...

AND NOT FIND_IN_SET(ship_method_exempt, '#session.customer_shipping_category#')

	SELECT
		Min(r.ship_range_from) AS min_range_from,
		Max(r.ship_range_to) AS max_range_to,
		m.ship_method_id,
		m.ship_method_name,
		m.ship_method_rate,
		r.ship_range_amount,
		r.ship_range_from,
		r.ship_range_to,
		c.ship_method_country_country_id,
		m.ship_method_sort,
		m.ship_method_calctype,
		m.ship_method_archive
	FROM
		(cw_ship_method_countries c
		INNER JOIN cw_ship_methods m
		ON c.ship_method_country_method_id = m.ship_method_id)
		LEFT JOIN cw_ship_ranges r
		ON m.ship_method_id = r.ship_range_method_id
	<!--- if looking up price by range, return only a single range --->
	WHERE 1=1
	<cfif arguments.match_range>
	AND (r.ship_range_from <= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">
		AND r.ship_range_to >= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
		<cfif arguments.localcalc_only eq true>OR NOT m.ship_method_calctype = 'localcalc'</cfif>
	</cfif>
	AND NOT FIND_IN_SET(ship_method_exempt, '#session.customer_shipping_category#')
	GROUP BY
		m.ship_method_id,
		m.ship_method_name,
		c.ship_method_country_country_id,
		m.ship_method_sort,
		m.ship_method_archive,
		m.ship_method_rate,
		m.ship_method_calctype,
		r.ship_range_amount,
		r.ship_range_from,
		r.ship_range_to
	HAVING (
			((Min(r.ship_range_from) <= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
			AND (Max(r.ship_range_to) >= <cfqueryparam cfsqltype="cf_sql_float" value="#rangeValue#">)
			AND (c.ship_method_country_country_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.ship_country_id#">)
			) 
			<cfif arguments.localcalc_only eq true>OR (NOT m.ship_method_calctype = 'localcalc' AND c.ship_method_country_country_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.ship_country_id#">)</cfif>
			)
		<cfif arguments.ship_method_id gt 0>
		AND m.ship_method_id = <cfqueryparam value="#arguments.ship_method_id#" cfsqltype="cf_sql_integer">
		</cfif>
		AND NOT (m.ship_method_archive = 1)
	ORDER BY
		m.ship_method_sort,
		m.ship_method_id,
		m.ship_method_name,
		c.ship_method_country_country_id,
		m.ship_method_archive,
		m.ship_method_rate,
		m.ship_method_calctype,
		r.ship_range_amount,
		Min(r.ship_range_from),
		Max(r.ship_range_to)

Open in new window

0
Comment
Question by:brihol44
  • 2
3 Comments
 
LVL 15

Expert Comment

by:gplana
ID: 39619124
I don'r really understand your question. Can you explain what is the issue? What you would like to get?

Also if possible please minimize your query just to make a minimal example of what is wrong...
0
 

Author Comment

by:brihol44
ID: 39619149
Hello, I want to filter out shipping methods where session.customer_shipping_category eq either "po, re, co". In the newly created column in shipping methods I have the following values to use for NOT pulling shipping methods that eq true to value of session.customer_shipping_category

1. po, rs
2. po
3. po
4. (empty)
5. (empty)
6. po, co
0
 
LVL 15

Accepted Solution

by:
gplana earned 200 total points
ID: 39619189
Then I think you want something like this:

SELECT *
FROM session
WHERE customer_shipping_category LIKE '%po%' OR customer_shipping_category LIKE '%re%' OR customer_shipping_categoryLIKE '%co%';

Open in new window


Please try it and let me know if this is what you want.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mysql update statement 3 33
insert into database through form with dynamic fields. 2 50
mysql date time 14 43
Very Large data in MYSQL 7 91
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question